Package org.apache.blur.thirdparty.thrift_0_9_0.protocol

Examples of org.apache.blur.thirdparty.thrift_0_9_0.protocol.TSimpleJSONProtocol$Context


    writeJSONInteger(VERSION);
    try {
      byte[] b = message.name.getBytes("UTF-8");
      writeJSONString(b);
    } catch (UnsupportedEncodingException uex) {
      throw new TException("JVM DOES NOT SUPPORT UTF-8");
    }
    writeJSONInteger(message.type);
    writeJSONInteger(message.seqid);
  }
View Full Code Here


  public void writeString(String str) throws TException {
    try {
      byte[] b = str.getBytes("UTF-8");
      writeJSONString(b);
    } catch (UnsupportedEncodingException uex) {
      throw new TException("JVM DOES NOT SUPPORT UTF-8");
    }
  }
View Full Code Here

                                       "Numeric data unexpectedly quoted");
        }
        return dub;
      }
      catch (UnsupportedEncodingException ex) {
        throw new TException("JVM DOES NOT SUPPORT UTF-8");
      }
    }
    else {
      if (context_.escapeNum()) {
        // This will throw - we should have had a quote if escapeNum == true
View Full Code Here

    String name;
    try {
      name = readJSONString(false).toString("UTF-8");
    }
    catch (UnsupportedEncodingException ex) {
      throw new TException("JVM DOES NOT SUPPORT UTF-8");
    }
    byte type = (byte) readJSONInteger();
    int seqid = (int) readJSONInteger();
    return new TMessage(name, type, seqid);
  }
View Full Code Here

  public String readString() throws TException {
    try {
      return readJSONString(false).toString("UTF-8");
    }
    catch (UnsupportedEncodingException ex) {
      throw new TException("JVM DOES NOT SUPPORT UTF-8");
    }
  }
View Full Code Here

    selectThread.start();
  }

  public void call(TAsyncMethodCall method) throws TException {
    if (!isRunning()) {
      throw new TException("SelectThread is not running");
    }
    method.prepareMethodCall();
    pendingCalls.add(method);
    selectThread.getSelector().wakeup();
  }
View Full Code Here

    setServing(true);

    while (!stopped_) {
      TTransport client = null;
      TProcessor processor = null;
      TTransport inputTransport = null;
      TTransport outputTransport = null;
      TProtocol inputProtocol = null;
      TProtocol outputProtocol = null;
      ServerContext connectionContext = null;
      try {
        client = serverTransport_.accept();
        if (client != null) {
          processor = processorFactory_.getProcessor(client);
          inputTransport = inputTransportFactory_.getTransport(client);
          outputTransport = outputTransportFactory_.getTransport(client);
          inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
          outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
          if (eventHandler_ != null) {
            connectionContext = eventHandler_.createContext(inputProtocol, outputProtocol, null);
          }
          while (true) {
            if (eventHandler_ != null) {
              eventHandler_.processContext(connectionContext, inputTransport, outputTransport);
            }
            if(!processor.process(inputProtocol, outputProtocol)) {
              break;
            }
          }
        }
      } catch (TTransportException ttx) {
View Full Code Here

      this.processorFactory = factory;
      return (T) this;
    }

    public T processor(TProcessor processor) {
      this.processorFactory = new TProcessorFactory(processor);
      return (T) this;
    }
View Full Code Here

    });
  }

  private Object execute(AsyncCall call) throws Exception {
    AsyncMethodCallback<?> realCallback = getRealAsyncMethodCallback(call._args);
    TAsyncClient client = newClient(call._clazz, call._connection);
    AsyncMethodCallback<?> retryingCallback = wrapCallback(realCallback, client, call._connection);
    resetArgs(call._args, retryingCallback);
    return call._method.invoke(client, call._args);
  }
View Full Code Here

    return (AsyncMethodCallback<?>) args[args.length - 1];
  }

  private TAsyncClient newClient(Class<?> c, Connection connection) throws InterruptedException {
    BlockingQueue<TAsyncClient> blockingQueue = getQueue(connection);
    TAsyncClient client = blockingQueue.poll();
    if (client != null) {
      return client;
    }

    AtomicInteger counter;
    synchronized (_numberOfConnections) {
      counter = _numberOfConnections.get(connection.getHost());
      if (counter == null) {
        counter = new AtomicInteger();
        _numberOfConnections.put(connection.getHost(), counter);
      }
    }

    synchronized (counter) {
      int numOfConnections = counter.get();
      while (numOfConnections >= _maxConnectionsPerHost) {
        client = blockingQueue.poll(_pollTime, TimeUnit.MILLISECONDS);
        if (client != null) {
          return client;
        }
        LOG.debug("Waiting for client number of connection [" + numOfConnections + "], max connection per host [" + _maxConnectionsPerHost + "]");
        numOfConnections = counter.get();
      }
      LOG.info("Creating a new client for [" + connection + "]");
      String name = c.getName();
      Constructor<?> constructor = _constructorCache.get(name);
      if (constructor == null) {
        String clientClassName = name.replace("$AsyncIface", "$AsyncClient");
        try {
          Class<?> clazz = Class.forName(clientClassName);
          constructor = clazz.getConstructor(new Class[] { TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class });
          _constructorCache.put(name, constructor);
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      }
      try {
        TNonblockingSocket transport = newTransport(connection);
        client = (TAsyncClient) constructor.newInstance(new Object[] { _protocolFactory, _clientManager, transport });
        client.setTimeout(_timeout);
        counter.incrementAndGet();
        return client;
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
View Full Code Here

TOP

Related Classes of org.apache.blur.thirdparty.thrift_0_9_0.protocol.TSimpleJSONProtocol$Context

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.