Package org.jredis.protocol

Examples of org.jredis.protocol.Response


   */
  @Override
  protected Response serviceRequest(Command cmd, byte[]... args)
      throws RedisException, ClientRuntimeException, ProviderException
  {
    Response response = null;
   
    try {
      // we're using a counting semaphore to remain within
      // bounds of the connection count
      // if more than cnt requests are being serviced, we block here
View Full Code Here


   */
  public JRedis sync () {
    return new JRedisSupport() {
      @Override
            protected Response serviceRequest (Command cmd, byte[]... args) throws RedisException, ClientRuntimeException, ProviderException {
        Response response = null;
        try {
                  response = JRedisPipeline.this.queueRequest(cmd, args).get();
                }
                catch (InterruptedException e) {
                  throw new ClientRuntimeException("Interrupted!", e);
View Full Code Here

   */
  public JRedis sync (final long timeout, final TimeUnit unit) {
    return new JRedisSupport() {
      @Override
            protected Response serviceRequest (Command cmd, byte[]... args) throws RedisException, ClientRuntimeException, ProviderException {
        Response response = null;
        try {
                  response = JRedisPipeline.this.queueRequest(cmd, args).get(timeout, unit);
                }
                catch (InterruptedException e) {
                  throw new ClientRuntimeException("Interrupted!", e);
View Full Code Here

      //
      Future<Response> pendingResponse = queueRequest(cmd, args);
     
      // wait for response
      //
      Response response;
        try {
          // This will block.
          response = pendingResponse.get();
        }
        catch (InterruptedException e) {
          e.printStackTrace();
          throw new ClientRuntimeException("on pendingResponse.get()", e);
        }
        catch (ExecutionException e) {
          if(e.getCause() instanceof RedisException) {
            throw (RedisException) e.getCause();
          }
          else {
            e.printStackTrace();
            throw new ProviderException("on pendingResponse.get()", e);
          }
        }
     
        // check response status
        //
    ResponseStatus status = Assert.notNull (response.getStatus(), "status from response object", ProviderException.class);
    if(status.isError()) {
      Log.error ("Error response for " + cmd.code + " => " + status.message());
      throw new RedisException(cmd, status.message());
    }
    /* this is handled by the super class */
 
View Full Code Here

  {
   
    if(!isConnected()) throw new NotConnectedException ("Not connected!");
   
    Request      request = null;
    Response    response = null;
    ResponseStatus  status = null;
   
    try {
      // 1 - Request
      //        Log.log("RedisConnection - requesting ..." + cmd.code);
     
      request = Assert.notNull(protocol.createRequest (cmd, args), "request object from handler", ProviderException.class);
      request.write(super.getOutputStream());

      // 2 - response
      //        Log.log("RedisConnection - read response ..." + cmd.code);
      response = Assert.notNull(protocol.createResponse(cmd), "response object from handler", ProviderException.class);
      response.read(super.getInputStream());

      //        break;
    }
    catch (ProviderException bug){
      Log.bug ("serviceRequest() -- ProviderException: " + bug.getLocalizedMessage());
      Log.log ("serviceRequest() -- closing connection ...");
      disconnect();
      throw bug;
    }
    catch (ClientRuntimeException cre) {
      Log.problem ("serviceRequest() -- ClientRuntimeException  => " + cre.getLocalizedMessage());
      reconnect();
     
      throw new ConnectionResetException ("Connection re-established but last request not processed:  " + cre.getCause().getLocalizedMessage());
    }
    catch (RuntimeException e){
      e.printStackTrace();
      Log.bug ("serviceRequest() -- *unexpected* RuntimeException: " + e.getLocalizedMessage());

      Log.log ("serviceRequest() -- closing connection ...");
      disconnect();

      throw new ClientRuntimeException("unexpected runtime exeption: " + e.getLocalizedMessage(), e);
    }
   
    // 3 - Status
    //
    status = Assert.notNull (response.getStatus(), "status from response object", ProviderException.class);
    if(status.isError()) {
      Log.error ("Error response for " + cmd.code + " => " + status.message());
      throw new RedisException(cmd, status.message());
    }
    else if(status.code() == ResponseStatus.Code.CIAO) {
View Full Code Here

    throws RedisException
  {
    if(!isConnected()) throw new NotConnectedException ("Not connected!");
   
    Request      request = null;
    Response    response = null;
    ResponseStatus  status = null;
    Protocol    protocol = Assert.notNull(getProtocolHandler(), "thread protocol handler", ProviderException.class);

    try {
      // 1 - Request
      //        Log.log("RedisConnection - requesting ..." + cmd.code);
     
      request = Assert.notNull(protocol.createRequest (cmd, args), "request object from handler", ProviderException.class);
      request.write(super.getOutputStream());

      // 2 - response
      //        Log.log("RedisConnection - read response ..." + cmd.code);
      response = Assert.notNull(protocol.createResponse(cmd), "response object from handler", ProviderException.class);
      response.read(super.getInputStream());

      //        break;
    }
    catch (ProviderException bug){
      Log.bug ("serviceRequest() -- ProviderException: " + bug.getLocalizedMessage());
      Log.log ("serviceRequest() -- closing connection ...");
      disconnect();
      throw bug;
    }
    catch (ClientRuntimeException cre) {
      Log.problem ("serviceRequest() -- ClientRuntimeException  => " + cre.getLocalizedMessage());
      reconnect();
     
      throw new ConnectionReset ("Connection re-established but last request not processed:  " + cre.getLocalizedMessage());
    }
    catch (RuntimeException e){
      e.printStackTrace();
      Log.bug ("serviceRequest() -- *unexpected* RuntimeException: " + e.getLocalizedMessage());

      Log.log ("serviceRequest() -- closing connection ...");
      disconnect();

      throw new ClientRuntimeException("unexpected runtime exeption: " + e.getLocalizedMessage(), e);
    }
    // 3 - Status
    //
    status = Assert.notNull (response.getStatus(), "status from response object", ProviderException.class);
    if(status.isError()) {
      Log.error ("Error response for " + cmd.code + " => " + status.message());
      throw new RedisException(cmd, status.message());
    }
    else if(status.code() == ResponseStatus.Code.CIAO) {
View Full Code Here

   * @see org.jredis.connector.Protocol#createResponse(org.jredis.Command)
   */
  @Override
  public Response createResponse(Command cmd) throws ProviderException, ClientRuntimeException {

    Response response = null;
    switch (cmd.responseType){
    case BOOLEAN:
      response = createBooleanResponse(cmd);
      break;
    case BULK:
View Full Code Here

//        @Override
        public void run () {
      Log.log("Pipeline thread <%s> started.", Thread.currentThread().getName());
          PendingRequest pending = null;
          while(true){
            Response response = null;
        try {
                  pending = pendingResponseQueue.take();
          try {
            response = protocol.createResponse(pending.cmd);
            response.read(getInputStream());
            pending.response = response;
            pending.completion.signal();
            if(response.getStatus().isError()) {
              Log.error ("(Asynch) Error response for " + pending.cmd.code + " => " + response.getStatus().message());
            }

          }
          catch (ProviderException bug){
            Log.error ("ProviderException: " + bug.getLocalizedMessage());
View Full Code Here

      Log.log("Pipeline <%s> thread for <%s> started.", Thread.currentThread().getName(), ChunkedPipelineConnection.this.toString());
      PendingCPRequest pending = null;
      //      while(work_flag.get()){
      while(work_flag){
        Response response = null;
        try {
          PendingCPRequest[] items = null;
          items = pendingResponseQueue.take();
          for(PendingCPRequest item : items) {
            if(item == null) { break; }
            pending = item;
            try {
              // TODO: here -- simplify REVU: ?
              response = protocol.createResponse(pending.cmd);
              response.read(getInputStream());
              pending.response = response;
              pending.completion.signal();
              if(response.getStatus().isError()) {
                Log.error ("(Asynch) Error response for " + pending.cmd.code + " => " + response.getStatus().message());
              }

            }

            // TODO: REVU: this in context of both connection and (general) errors.
View Full Code Here

    Log.debug("HeartbeatJinn thread <%s> started.", Thread.currentThread().getName());
   
    while (mustBeat.get()) {
      try {
        if(connected.get()){  // << buggy: quit needs to propagate down here.
          Response response = null;
          try {
            switch (modality){
            case Asynchronous:
              Future<Response> fResponse = conn.queueRequest(Command.PING);
              response = fResponse.get();
              break;
            case Synchronous:
              response = conn.serviceRequest(Command.PING);
              break;
            case Monitor:
            case PubSub:
              throw new ProviderException(String.format("%s connector not supported", modality.name()));
            }
            if(!response.isError()){
//              if(conn.getSpec().getLogLevel().equals(LogLevel.DEBUG))
              Log.debug (String.format("<%s> is alive", conn));
            }
            else {
              String errmsg = String.format("Error response on PING: %s", response.getStatus().toString());
              Log.error(errmsg);
              throw new ClientRuntimeException(errmsg)// NOTE: can't be sure this is a protocol BUG .. so CRE instead
            }
          }
          catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.jredis.protocol.Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.