Package org.jredis.protocol

Examples of org.jredis.protocol.Protocol


          NotSupportedException.class);
      break;
    }
    // instantiate protocol handler object
    //
    Protocol handler = null;
    try {
      handler = (Protocol) handlerClass.getConstructor().newInstance();
      Assert.isTrue(handler.isCompatibleWithVersion(version.id), "supports version " + version.id, ProviderException.class);
    }
    catch (SecurityException e) {
      Log.problem("SecurityException when attempting to instantiate a " + handlerClass.getCanonicalName());
      throw new ClientRuntimeException ("Check the security policy -- we have a problem => "+ e.getLocalizedMessage(), e);
    }
View Full Code Here


    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){
View Full Code Here

      throw new NotConnectedException ("Not connected!");

    if(pendingQuit)
      throw new ClientRuntimeException("Pipeline shutting down: Quit in progess; no further requests are accepted.");

    Protocol    protocol = Assert.notNull(getProtocolHandler(), "thread protocol handler", ProviderException.class);
    //    Log.log("protocol %d@%s", protocol.hashCode(), protocol.getClass());

    final boolean sendreq =
      cmd.responseType != ResponseType.VIRTUAL &&
      cmd.responseType != ResponseType.NOP;

    /* setup send buffer if necessary */
    int    reqbyteslen = 0;
    if(sendreq) {
      reqbyteslen = ProtocolHelper.calcReqBuffSize(cmd, args);
    }

    /* PendingCPRequest provides transparent hook to force flush on future get(..) */
    final PendingCPRequest   queuedRequest = new PendingCPRequest(this, cmd);

    /* possibly silly optimization, pulled out of sync block */
    final OutputStream out = getOutputStream();
    final boolean isflush = cmd == Command.CONN_FLUSH;
    final boolean exceeds = reqbyteslen > CHUNK_BUFF_SIZE;
    final boolean isquit = cmd == Command.QUIT;

    /* auth is used on connector initialization and must be sent asap */
    final boolean doflush =
      cmd == Command.AUTH   ||
      cmd == Command.SELECT   ||
      isquit          ||
      isflush;

    try {
      requestlock.lock();
     
      /* ======== CRITICAL BLOCK ====== */
     
      /* 4 byte control word is [ idx | off ] */
      /* chunk_ctl_word is contended and must be accessed only inside of critical block */
      final int __ctl_word = ctl_word;  // REVU: opportunity ..
      int idx = __ctl_word >> 16;
      int off = __ctl_word & 0x0000FFFF;

      boolean overflows = exceeds || off + reqbyteslen > CHUNK_BUFF_SIZE ? true : false;
     
      if(overflows) {
        out.write(chunkbuff, 0, off);
        out.flush();
        off = 0;
       
        pendingResponseQueue.add(chunkqueue);
        chunkqueue = new PendingCPRequest[CHUNK_Q_SIZE];
        idx = 0;
      }

      if(sendreq){
        if(exceeds) {
          /* can optimize and dispense with new byte[] -- only for large payloads */
          /* chunkqueue should be empty and idx 0 : assert for now */
          out.write(protocol.createRequestBuffer(cmd, args));
          out.flush();
          chunkqueue[0] = queuedRequest;
          final PendingCPRequest[] oneoffitem =  new PendingCPRequest[1];
          oneoffitem[0] = queuedRequest;
          pendingResponseQueue.add(oneoffitem);
View Full Code Here

    @Override
    public void run () {
      thread.compareAndSet(null, Thread.currentThread());
      alive_flag.compareAndSet(false, true);
      /** Response handler thread specific protocol handler -- optimize fencing */
      Protocol protocol = Assert.notNull (newProtocolHandler(), "the delegate protocol handler", ClientRuntimeException.class);

      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());
View Full Code Here

       */

        public void run () {
      Log.log("AsyncConnection processor thread <%s> started.", Thread.currentThread().getName());
          /** Response handler thread specific protocol handler -- optimize fencing */
          Protocol protocol = Assert.notNull (newProtocolHandler(), "the delegate protocol handler", ClientRuntimeException.class);
          PendingRequest pending = null;
          final BlockingQueue<PendingRequest>  _pendingQueue = getPendingQueue();
          while(true){
        try {
                  pending = _pendingQueue.take();
          try {
            Request request = Assert.notNull(protocol.createRequest (pending.cmd, pending.args), "request object from handler", ProviderException.class);
            request.write(getOutputStream());
           
            pending.response = protocol.createResponse(pending.cmd);
            pending.response.read(getInputStream());
           
            pending.completion.signal();
            if(pending.response.getStatus().isError()) {
              Log.error ("(Asynch) Error response for " + pending.cmd.code + " => " + pending.response.getStatus().message());
View Full Code Here

//    this.protocol = notNull(protocolHandler, "protocolHandler for ConnectionBase", ClientRuntimeException.class);
//  }
 
  final protected Protocol getProtocolHandler() {
    if(thrdProtocol.get() == null) {
      final Protocol protocol = Assert.notNull (newProtocolHandler(), "the delegate protocol handler", ClientRuntimeException.class);
        thrdProtocol.set(protocol);
    }
//    System.out.format("<<<<<<<<<<< PROTOCOL HANDLER: %s\n", thrdProtocol.get());
    return notNull(thrdProtocol.get(), "protocolHandler for ConnectionBase", ClientRuntimeException.class);
  }
View Full Code Here

      throw new NotConnectedException ("Not connected!");
   
    if(pendingQuit)
      throw new ClientRuntimeException("Pipeline shutting down: Quit in progess; no further requests are accepted.");
   
    Protocol    protocol = Assert.notNull(getProtocolHandler(), "thread protocol handler", ProviderException.class);
    Request     request = Assert.notNull(protocol.createRequest (cmd, args), "request object from handler", ProviderException.class);
    PendingRequest   pendingResponse = new PendingRequest(cmd);
   
    if(cmd == Command.CONN_FLUSH) {
      Log.log("%s not supported -- ignored", cmd.code);
      return pendingResponse;
View Full Code Here

        @Override
        public void run () {
          thread.compareAndSet(null, Thread.currentThread());
          alive_flag.compareAndSet(false, true);
          /** Response handler thread specific protocol handler -- optimize fencing */
          Protocol protocol = Assert.notNull (newProtocolHandler(), "the delegate protocol handler", ClientRuntimeException.class);
         
      Log.log("Pipeline <%s> thread for <%s> started.", Thread.currentThread().getName(), PipelineConnectionBase.this.toString());
          PendingRequest pending = null;
          while(work_flag.get()){
            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());
View Full Code Here

TOP

Related Classes of org.jredis.protocol.Protocol

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.