org.apache.avro.ipc.NettyServer Java Examples

The following examples show how to use org.apache.avro.ipc.NettyServer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AvroProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Override
protected <T> Runnable doExport(T impl, Class<T> type, URL url)
        throws RpcException {

    logger.info("impl => " + impl.getClass());
    logger.info("type => " + type.getName());
    logger.info("url => " + url);

    final Server server = new NettyServer(new ReflectResponder(type, impl),
            new InetSocketAddress(url.getHost(), url.getPort()));
    server.start();

    return new Runnable() {
        public void run() {
            try {
                logger.info("Close Avro Server");
                server.close();
            } catch (Throwable e) {
                logger.warn(e.getMessage(), e);
            }
        }
    };
}
 
Example #2
Source File: RunLocalTest.java    From hadoop-arch-book with Apache License 2.0 6 votes vote down vote up
public static Server startTestFlumeServer(int port) {
  Responder responder = new SpecificResponder(AvroSourceProtocol.class,
          new OKAvroHandler());
  Server server = new NettyServer(responder,
            new InetSocketAddress("127.0.0.1", port));

  server.start();
  LOG.info("Server started on test flume server hostname: localhost, port: " + port);

  try {

    Thread.sleep(1000L);

  } catch (InterruptedException ex) {
    LOG.error("Thread interrupted. Exception follows.", ex);
    Thread.currentThread().interrupt();
  }

  return server;
}
 
Example #3
Source File: AvroRpcResourceManager.java    From oodt with Apache License 2.0 6 votes vote down vote up
@Override
public void startUp() throws Exception {
    try {
        configurationManager.loadConfiguration();
    } catch (Exception e) {
        logger.error("Unable to load configuration", e);
        throw new IOException("Unable to load configuration", e);
    }

    String schedulerClassStr = System.getProperty("resource.scheduler.factory",
            "org.apache.oodt.cas.resource.scheduler.LRUSchedulerFactory");
    scheduler = GenericResourceManagerObjectFactory.getSchedulerServiceFromFactory(schedulerClassStr);

    // start up the scheduler
    executorService = Executors.newSingleThreadExecutor();
    executorService.submit(scheduler);

    // start up the web server
    server = new NettyServer(new SpecificResponder(org.apache.oodt.cas.resource.structs.avrotypes.ResourceManager.class, this),
            new InetSocketAddress(this.port));
    server.start();

    logger.info("Resource Manager started by {}", System.getProperty("user.name", "unknown"));
}
 
Example #4
Source File: AvroSource.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Override
public void start() {
  logger.info("Starting {}...", this);

  Responder responder = new SpecificResponder(AvroSourceProtocol.class, this);

  NioServerSocketChannelFactory socketChannelFactory = initSocketChannelFactory();

  ChannelPipelineFactory pipelineFactory = initChannelPipelineFactory();

  server = new NettyServer(responder, new InetSocketAddress(bindAddress, port),
        socketChannelFactory, pipelineFactory, null);

  connectionCountUpdater = Executors.newSingleThreadScheduledExecutor();
  server.start();
  sourceCounter.start();
  super.start();
  final NettyServer srv = (NettyServer)server;
  connectionCountUpdater.scheduleWithFixedDelay(new Runnable(){

    @Override
    public void run() {
      sourceCounter.setOpenConnectionCount(
              Long.valueOf(srv.getNumActiveConnections()));
    }
  }, 0, 60, TimeUnit.SECONDS);

  logger.info("Avro source {} started.", getName());
}
 
Example #5
Source File: TestAvroSink.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
private Server createServer(AvroSourceProtocol protocol)
    throws IllegalAccessException, InstantiationException {

  Server server = new NettyServer(new SpecificResponder(
      AvroSourceProtocol.class, protocol), new InetSocketAddress(
      hostname, port));

  return server;
}
 
Example #6
Source File: TestAvroSink.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
private Server createSslServer(AvroSourceProtocol protocol)
    throws IllegalAccessException, InstantiationException {
  Server server = new NettyServer(new SpecificResponder(
      AvroSourceProtocol.class, protocol), new InetSocketAddress(hostname, port),
          new NioServerSocketChannelFactory(
                  Executors.newCachedThreadPool(),
                  Executors.newCachedThreadPool()),
          new SSLChannelPipelineFactory(),
          null);

  return server;
}
 
Example #7
Source File: TestEmbeddedAgent.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  headers = Maps.newHashMap();
  headers.put("key1", "value1");
  body = "body".getBytes(Charsets.UTF_8);

  int port = findFreePort();
  eventCollector = new EventCollector();
  Responder responder = new SpecificResponder(AvroSourceProtocol.class,
      eventCollector);
  nettyServer = new NettyServer(responder,
            new InetSocketAddress(HOSTNAME, port));
  nettyServer.start();

  // give the server a second to start
  Thread.sleep(1000L);

  properties = Maps.newHashMap();
  properties.put("channel.type", "memory");
  properties.put("channel.capacity", "200");
  properties.put("sinks", "sink1 sink2");
  properties.put("sink1.type", "avro");
  properties.put("sink2.type", "avro");
  properties.put("sink1.hostname", HOSTNAME);
  properties.put("sink1.port", String.valueOf(port));
  properties.put("sink2.hostname", HOSTNAME);
  properties.put("sink2.port", String.valueOf(port));
  properties.put("processor.type", "load_balance");

  agent = new EmbeddedAgent("test-" + serialNumber.incrementAndGet());
}
 
Example #8
Source File: AvroFileManagerServer.java    From oodt with Apache License 2.0 5 votes vote down vote up
@Override
public boolean startUp() throws Exception {
    server = new NettyServer(new SpecificResponder(AvroFileManager.class,this),new InetSocketAddress(this.port));
    server.start();
    try {
        this.fileManager = new FileManager();
        this.loadConfiguration();
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
 
Example #9
Source File: FlumePersistentAppenderTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public EventCollector(final int port) {
    final Responder responder = new SpecificResponder(AvroSourceProtocol.class, this);
    nettyServer = new NettyServer(responder, new InetSocketAddress(HOSTNAME, port));
    nettyServer.start();
}
 
Example #10
Source File: FlumeEmbeddedAppenderTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public EventCollector(final int port) {
    final Responder responder = new SpecificResponder(AvroSourceProtocol.class, this);
    System.out.println("Collector listening on port " + port);
    nettyServer = new NettyServer(responder, new InetSocketAddress(HOSTNAME, port));
    nettyServer.start();
}
 
Example #11
Source File: FlumePersistentPerf.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public EventCollector(final int port) {
    final Responder responder = new SpecificResponder(AvroSourceProtocol.class, this);
    nettyServer = new NettyServer(responder, new InetSocketAddress(HOSTNAME, port));
    nettyServer.start();
}
 
Example #12
Source File: FlumeEmbeddedAgentTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public EventCollector(final int port) {
    final Responder responder = new SpecificResponder(AvroSourceProtocol.class, this);
    nettyServer = new NettyServer(responder, new InetSocketAddress(HOSTNAME, port));
    nettyServer.start();
}
 
Example #13
Source File: ProxyServerAvroRPC.java    From netty-cookbook with Apache License 2.0 4 votes vote down vote up
static void startServer() throws IOException {
	server = new NettyServer(new SpecificResponder(Mail.class,new MailImpl()), new InetSocketAddress(10000));
}
 
Example #14
Source File: ProxyServerAvroRPC.java    From netty-cookbook with Apache License 2.0 4 votes vote down vote up
static void startServer() throws IOException {
	server = new NettyServer(new SpecificResponder(Mail.class,new MailImpl()), new InetSocketAddress(10000));
}
 
Example #15
Source File: TCPServerSource.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Override
protected List<ConfigIssue> init() {
  List<ConfigIssue> issues = new ArrayList<>();

  config.dataFormatConfig.stringBuilderPoolSize = config.numThreads;

  if (config.enableEpoll && !Epoll.isAvailable()) {
    issues.add(getContext().createConfigIssue(Groups.TCP.name(), CONF_PREFIX + "enableEpoll", Errors.TCP_05));
  }
  final String portsField = "ports";
  if (config.ports.isEmpty()) {
    issues.add(getContext().createConfigIssue(Groups.TCP.name(), portsField, Errors.TCP_02));
  } else {
    for (String candidatePort : config.ports) {
      try {
        int port = Integer.parseInt(candidatePort.trim());
        if (port > 0 && port < 65536) {
          if (port < 1024) {
            privilegedPortUsage = true; // only for error handling purposes
          }
          addresses.add(new InetSocketAddress(port));
        } else {
          issues.add(getContext().createConfigIssue(Groups.TCP.name(), portsField, Errors.TCP_03, port));
        }
      } catch (NumberFormatException ex) {
        issues.add(getContext().createConfigIssue(Groups.TCP.name(), portsField, Errors.TCP_03, candidatePort));
      }
    }
  }

  if (issues.isEmpty()) {
    if (addresses.isEmpty()) {
      issues.add(getContext().createConfigIssue(Groups.TCP.name(), portsField, Errors.TCP_09));
    } else {
      if (config.tlsConfigBean.isEnabled()) {
        boolean tlsValid = config.tlsConfigBean.init(
            getContext(),
            Groups.TLS.name(),
            CONF_PREFIX + "tlsConfigBean.",
            issues
        );
        if (!tlsValid) {
          return issues;
        }
      }

      final boolean elValid = validateEls(issues);
      if (!elValid) {
        return issues;
      }

      validateTcpConfigs(issues);
      if (issues.size() > 0) {
        return issues;
      }

      if (config.tcpMode == TCPMode.FLUME_AVRO_IPC) {
        config.dataFormatConfig.init(
            getContext(),
            config.dataFormat,
            Groups.TCP.name(),
            CONF_PREFIX + "dataFormatConfig",
            config.maxMessageSize,
            issues
        );
        parserFactory = config.dataFormatConfig.getParserFactory();

        final int avroIpcPort = Integer.parseInt(config.ports.get(0));
        final SpecificResponder avroIpcResponder = new SpecificResponder(
            AvroSourceProtocol.class,
            new SDCFlumeAvroIpcProtocolHandler(getContext(), parserFactory, pipelineIdsToFail::put)
        );

        // this uses Netty 3.x code to help avoid rewriting a lot in our own stage lib
        // Netty 3.x and 4.x (which we use for the other modes) can coexist on the same classpath, so should be OK
        avroIpcServer = new NettyServer(
            avroIpcResponder,
            new InetSocketAddress(config.bindAddress, avroIpcPort)
        );

        avroIpcServer.start();
      } else {
        createAndStartTCPServer(issues, portsField);
      }
    }
  }
  return issues;
}
 
Example #16
Source File: Application.java    From skywalking with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    SpecificResponder responder = new SpecificResponder(Greeter.class, new GreeterImpl());
    NettyServer server = new NettyServer(responder, new InetSocketAddress(9018));
    server.start();
}
 
Example #17
Source File: AvroRpcBatchStub.java    From oodt with Apache License 2.0 3 votes vote down vote up
public AvroRpcBatchStub(int port) throws Exception {


        this.port = port;

        // start up the web server
        server = new NettyServer(new SpecificResponder(AvroIntrBatchmgr.class,this), new InetSocketAddress(this.port));
        server.start();

        jobThreadMap = new HashMap();

        LOG.log(Level.INFO, "AvroRpc Batch Stub started by "
                + System.getProperty("user.name", "unknown"));
    }