Java 类org.apache.thrift.server.ServerContext 实例源码

项目:metacat    文件:CatalogThriftEventHandler.java   
/**
 * {@inheritDoc}
 */
@Override
public ServerContext createContext(final TProtocol input, final TProtocol output) {
    final String userName = "metacat-thrift-interface";
    String clientHost = null; //requestContext.getHeaderString("X-Forwarded-For");
    final long requestThreadId = Thread.currentThread().getId();

    final TTransport transport = input.getTransport();
    if (transport instanceof TSocket) {
        final TSocket thriftSocket = (TSocket) transport;
        clientHost = thriftSocket.getSocket().getInetAddress().getHostAddress();
    }

    final CatalogServerRequestContext context = new CatalogServerRequestContext(
        userName,
        null,
        clientHost,
        null,
        "hive",
        requestThreadId
    );
    MetacatContextManager.setContext(context);
    return context;
}
项目:mlib    文件:ServerEventHandlerImpl.java   
@Override
public ServerContext createContext(TProtocol input, TProtocol output) {
    String clientName = null;
    if (input.getTransport() instanceof TSocket) { // tls
        try {
            clientName = ((SSLSocket) ((TSocket) input.getTransport()).getSocket())
                            .getSession().getPeerCertificateChain()[0].getSubjectDN().getName();
        } catch (SSLPeerUnverifiedException e) {
            log.error(e.getMessage(), e);
        }
        log.info("createContext: " + clientName);
    }
    return null;
}
项目:incubator-sentry    文件:InternalSentrySrv.java   
/**
 * Thrift callback when a new client is connecting
 */
@Override
public ServerContext createContext(TProtocol inputProto,
    TProtocol outputProto) {
  clientList.add(clientId.incrementAndGet());
  LOGGER.info("Client Connected: " + clientId.get());
  return new SentryServerContext(clientId.get());
}
项目:incubator-sentry    文件:InternalSentrySrv.java   
/**
 * Thrift callback when a client is disconnecting
 */
@Override
public void deleteContext(ServerContext arg0, TProtocol arg1, TProtocol arg2) {
  clientList.remove(((SentryServerContext) arg0).getContextId());
  LOGGER.info("Client Disonnected: "
      + ((SentryServerContext) arg0).getContextId());
}
项目:metacat    文件:CatalogThriftEventHandler.java   
/**
 * {@inheritDoc}
 */
@Override
public void deleteContext(final ServerContext serverContext, final TProtocol input, final TProtocol output) {
    validateRequest((CatalogServerRequestContext) serverContext);
    MetacatContextManager.removeContext();
}
项目:metacat    文件:CatalogThriftEventHandler.java   
/**
 * {@inheritDoc}
 */
@Override
public void processContext(final ServerContext serverContext, final TTransport inputTransport,
    final TTransport outputTransport) {
    validateRequest((CatalogServerRequestContext) serverContext);
}
项目:trpc    文件:TrpcRegistryEventHandler.java   
@Override
public ServerContext createContext(TProtocol tProtocol, TProtocol tProtocol1) {
    return null;
}
项目:trpc    文件:TrpcRegistryEventHandler.java   
@Override
public void deleteContext(ServerContext serverContext, TProtocol tProtocol, TProtocol tProtocol1) {
}
项目:trpc    文件:TrpcRegistryEventHandler.java   
@Override
public void processContext(ServerContext serverContext, TTransport tTransport, TTransport tTransport1) {
}
项目:gemfirexd-oss    文件:GfxdThriftServerThreadPool.java   
/**
 * Loops on processing a client forever
 */
@Override
public void run() {
  TProcessor processor = null;
  TTransport inputTransport = null;
  TTransport outputTransport = null;
  TProtocol inputProtocol = null;
  TProtocol outputProtocol = null;

  final TServerEventHandler eventHandler = getEventHandler();
  ServerContext connectionContext = null;

  final ConnectionListener listener = connListener;
  final TTransport client = this.client;
  Socket clientSocket = null;

  try {
    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);
    }
    // register with ConnectionListener
    if (listener != null) {
      if (client instanceof GfxdTSocket) {
        clientSocket = ((GfxdTSocket)client).getSocket();
      }
      else if (client instanceof TSocket) {
        clientSocket = ((TSocket)client).getSocket();
      }
      listener.connectionOpened(clientSocket, this.connectionNumber);
    }
    // we check stopped_ first to make sure we're not supposed to be
    // shutting down. this is necessary for graceful shutdown.
    while (true) {

      if (eventHandler != null) {
        eventHandler.processContext(connectionContext, inputTransport,
            outputTransport);
      }

      if (stopped || !processor.process(inputProtocol, outputProtocol)) {
        break;
      }
    }
  } catch (TTransportException tte) {
    // Assume the client died and continue silently
  } catch (TException te) {
    LOGGER.error("Thrift error occurred during processing of message.", te);
  } catch (Exception e) {
    LOGGER.error("Error occurred during processing of message.", e);
  }

  if (eventHandler != null) {
    eventHandler.deleteContext(connectionContext, inputProtocol,
        outputProtocol);
  }

  if (inputTransport != null) {
    inputTransport.close();
  }

  if (outputTransport != null) {
    outputTransport.close();
  }

  // deregister with ConnectionListener
  if (listener != null) {
    listener.connectionClosed(clientSocket, this.connectionNumber);
  }
}
项目:ikasoa    文件:ConfigurationTest.java   
@Override
public ServerContext createContext(TProtocol arg0, TProtocol arg1) {
    return null;
}
项目:ikasoa    文件:ConfigurationTest.java   
@Override
public void deleteContext(ServerContext arg0, TProtocol arg1, TProtocol arg2) {
    // Do nothing
}
项目:ikasoa    文件:ConfigurationTest.java   
@Override
public void processContext(ServerContext arg0, TTransport arg1, TTransport arg2) {
    // Do nothing
}
项目:gemfirexd-oss    文件:GfxdThriftServerThreadPool.java   
/**
 * Loops on processing a client forever
 */
@Override
public void run() {
  TProcessor processor = null;
  TTransport inputTransport = null;
  TTransport outputTransport = null;
  TProtocol inputProtocol = null;
  TProtocol outputProtocol = null;

  final TServerEventHandler eventHandler = getEventHandler();
  ServerContext connectionContext = null;

  final ConnectionListener listener = connListener;
  final TTransport client = this.client;
  Socket clientSocket = null;

  try {
    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);
    }
    // register with ConnectionListener
    if (listener != null) {
      if (client instanceof GfxdTSocket) {
        clientSocket = ((GfxdTSocket)client).getSocket();
      }
      else if (client instanceof TSocket) {
        clientSocket = ((TSocket)client).getSocket();
      }
      listener.connectionOpened(clientSocket, this.connectionNumber);
    }
    // we check stopped_ first to make sure we're not supposed to be
    // shutting down. this is necessary for graceful shutdown.
    while (true) {

      if (eventHandler != null) {
        eventHandler.processContext(connectionContext, inputTransport,
            outputTransport);
      }

      if (stopped || !processor.process(inputProtocol, outputProtocol)) {
        break;
      }
    }
  } catch (TTransportException tte) {
    // Assume the client died and continue silently
  } catch (TException te) {
    LOGGER.error("Thrift error occurred during processing of message.", te);
  } catch (Exception e) {
    LOGGER.error("Error occurred during processing of message.", e);
  }

  if (eventHandler != null) {
    eventHandler.deleteContext(connectionContext, inputProtocol,
        outputProtocol);
  }

  if (inputTransport != null) {
    inputTransport.close();
  }

  if (outputTransport != null) {
    outputTransport.close();
  }

  // deregister with ConnectionListener
  if (listener != null) {
    listener.connectionClosed(clientSocket, this.connectionNumber);
  }
}
项目:mlib    文件:ServerEventHandlerImpl.java   
@Override
public void deleteContext(ServerContext serverContext, TProtocol input, TProtocol output) {
    log.info("deleteContext");
}
项目:mlib    文件:ServerEventHandlerImpl.java   
@Override
public void processContext(ServerContext serverContext, TTransport inputTransport, TTransport outputTransport) {
    log.info("processContext: ");
}
项目:pinpoint    文件:EchoTestServer.java   
@Override
public ServerContext createContext(TProtocol tProtocol, TProtocol tProtocol1) {
    return null;
}
项目:incubator-sentry    文件:InternalSentrySrv.java   
@Override
public void processContext(ServerContext arg0, TTransport arg1,
    TTransport arg2) {
}
项目:pinpoint    文件:EchoTestServer.java   
@Override
public void deleteContext(ServerContext serverContext, TProtocol tProtocol, TProtocol tProtocol1) {

}
项目:pinpoint    文件:EchoTestServer.java   
@Override
public void processContext(ServerContext serverContext, TTransport tTransport, TTransport tTransport1) {

}