org.apache.avro.ipc.specific.SpecificRequestor Java Examples

The following examples show how to use org.apache.avro.ipc.specific.SpecificRequestor. 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: CaseController.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/healthCheck")
@ResponseBody
public String healthCheck() throws IOException {
    try {
        nettyClient = SpecificRequestor.getClient(Greeter.class, new NettyTransceiver(new InetSocketAddress("localhost", 9018)));
        return SUCCESS;
    } catch (Exception e) {
        throw e;
    }
}
 
Example #2
Source File: ClientAvroRPC.java    From netty-cookbook with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {      
	if(args.length < 3){
		args = new String[] {"[email protected]","[email protected]","Hello !"};
	}
    NettyTransceiver client = new NettyTransceiver(new InetSocketAddress(10000));     
    Mail proxy = (Mail) SpecificRequestor.getClient(Mail.class, client);
    LogUtil.println("ClientAvroRPC built OK, got proxy, ready to send data ...");     
    Message message = new Message();
    message.setTo(new Utf8(args[0]));
    message.setFrom(new Utf8(args[1]));
    message.setBody(new Utf8(args[2]));
    LogUtil.println("Calling proxy.send with message:  " + message.toString());
    LogUtil.println("Result from server: " + proxy.send(message)); 
    client.close();        
}
 
Example #3
Source File: ClientAvroRPC.java    From netty-cookbook with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {      
	if(args.length < 3){
		args = new String[] {"[email protected]","[email protected]","Hello !"};
	}
    NettyTransceiver client = new NettyTransceiver(new InetSocketAddress(10000));     
    Mail proxy = (Mail) SpecificRequestor.getClient(Mail.class, client);
    LogUtil.println("ClientAvroRPC built OK, got proxy, ready to send data ...");     
    Message message = new Message();
    message.setTo(new Utf8(args[0]));
    message.setFrom(new Utf8(args[1]));
    message.setBody(new Utf8(args[2]));
    LogUtil.println("Calling proxy.send with message:  " + message.toString());
    LogUtil.println("Result from server: " + proxy.send(message)); 
    client.close();        
}
 
Example #4
Source File: AvroFileManagerClient.java    From oodt with Apache License 2.0 5 votes vote down vote up
public AvroFileManagerClient(final URL url, boolean testConnection) throws ConnectionException {
    //setup the and start the client
    try {
        this.fileManagerUrl = url;
        InetSocketAddress inetSocketAddress = new InetSocketAddress(url.getHost(), this.fileManagerUrl.getPort());
        this.client = new NettyTransceiver(inetSocketAddress, 40000L);
        proxy = (AvroFileManager) SpecificRequestor.getClient(AvroFileManager.class, client);
    } catch (IOException e) {
        logger.error("Error occurred when creating file manager: {}", url, e);
    }

    if (testConnection && !isAlive()) {
        throw new ConnectionException("Exception connecting to filemgr: [" + this.fileManagerUrl + "]");
    }
}
 
Example #5
Source File: AvroRpcWorkflowManagerClient.java    From oodt with Apache License 2.0 5 votes vote down vote up
public AvroRpcWorkflowManagerClient(URL url){
    workflowManagerUrl = url;
    try {
        client = new HttpTransceiver(url);
        proxy = SpecificRequestor.getClient(org.apache.oodt.cas.workflow.struct.avrotypes.WorkflowManager.class, client);
    } catch (IOException e) {
        logger.error("Error occurred when creating client for: {}", url, e);
    }
    logger.info("Client created successfully for workflow manager URL: {}", url);
}
 
Example #6
Source File: AvroRpcWorkflowManagerClient.java    From oodt with Apache License 2.0 5 votes vote down vote up
@Override
public void setWorkflowManagerUrl(URL workflowManagerUrl) {
    this.workflowManagerUrl = workflowManagerUrl;
    try {
        client = new NettyTransceiver(new InetSocketAddress(workflowManagerUrl.getPort()));
        proxy = SpecificRequestor.getClient(org.apache.oodt.cas.workflow.struct.avrotypes.WorkflowManager.class, client);
    } catch (IOException e) {
        logger.error("Error occurred when setting workflow manager url: {}", workflowManagerUrl, e);
    }

}
 
Example #7
Source File: TestTCPServerSource.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Test
public void flumeAvroIpc() throws StageException, IOException, ExecutionException, InterruptedException {

  final Charset charset = Charsets.UTF_8;
  final TCPServerSourceConfig configBean = createConfigBean(charset);
  configBean.tcpMode = TCPMode.FLUME_AVRO_IPC;
  configBean.dataFormat = DataFormat.TEXT;
  configBean.bindAddress = "0.0.0.0";

  final int batchSize = 5;
  final String outputLane = "output";

  final TCPServerSource source = new TCPServerSource(configBean);
  final PushSourceRunner runner = new PushSourceRunner.Builder(TCPServerDSource.class, source)
      .addOutputLane(outputLane)
      .setOnRecordError(OnRecordError.TO_ERROR)
      .build();

  runner.runInit();

  runner.runProduce(Collections.emptyMap(), batchSize, out -> {
    final Map<String, List<Record>> outputMap = out.getRecords();
    assertThat(outputMap, hasKey(outputLane));
    final List<Record> records = outputMap.get(outputLane);
    assertThat(records, hasSize(batchSize));
    for (int i = 0; i < batchSize; i++) {
      assertThat(
          records.get(i).get("/" + TextDataParserFactory.TEXT_FIELD_NAME),
          fieldWithValue(getFlumeAvroIpcEventName(i))
      );
    }
    runner.setStop();
  });

  final AvroSourceProtocol client = SpecificRequestor.getClient(AvroSourceProtocol.class, new NettyTransceiver(new InetSocketAddress("localhost", Integer.parseInt(configBean.ports.get(0)))));

  List<AvroFlumeEvent> events = new LinkedList<>();
  for (int i = 0; i < batchSize; i++) {
    AvroFlumeEvent avroEvent = new AvroFlumeEvent();

    avroEvent.setHeaders(new HashMap<CharSequence, CharSequence>());
    avroEvent.setBody(ByteBuffer.wrap(getFlumeAvroIpcEventName(i).getBytes()));
    events.add(avroEvent);
  }

  Status status = client.appendBatch(events);

  assertThat(status, equalTo(Status.OK));

  runner.waitOnProduce();
}
 
Example #8
Source File: TestAvroSource.java    From mt-flume with Apache License 2.0 4 votes vote down vote up
private void doRequest(boolean serverEnableCompression, boolean clientEnableCompression, int compressionLevel) throws InterruptedException, IOException {
  boolean bound = false;

  for (int i = 0; i < 100 && !bound; i++) {
    try {
      Context context = new Context();
      context.put("port", String.valueOf(selectedPort = 41414 + i));
      context.put("bind", "0.0.0.0");
      context.put("threads", "50");
      if (serverEnableCompression) {
        context.put("compression-type", "deflate");
      } else {
        context.put("compression-type", "none");
      }

      Configurables.configure(source, context);

      source.start();
      bound = true;
    } catch (ChannelException e) {
      /*
       * NB: This assume we're using the Netty server under the hood and the
       * failure is to bind. Yucky.
       */
    }
  }

  Assert
      .assertTrue("Reached start or error", LifecycleController.waitForOneOf(
          source, LifecycleState.START_OR_ERROR));
  Assert.assertEquals("Server is started", LifecycleState.START,
      source.getLifecycleState());

  AvroSourceProtocol client;
  if (clientEnableCompression) {
    client = SpecificRequestor.getClient(
        AvroSourceProtocol.class, new NettyTransceiver(new InetSocketAddress(
            selectedPort), new CompressionChannelFactory(6)));
  } else {
    client = SpecificRequestor.getClient(
        AvroSourceProtocol.class, new NettyTransceiver(new InetSocketAddress(
            selectedPort)));
  }

  AvroFlumeEvent avroEvent = new AvroFlumeEvent();

  avroEvent.setHeaders(new HashMap<CharSequence, CharSequence>());
  avroEvent.setBody(ByteBuffer.wrap("Hello avro".getBytes()));

  Status status = client.append(avroEvent);

  Assert.assertEquals(Status.OK, status);

  Transaction transaction = channel.getTransaction();
  transaction.begin();

  Event event = channel.take();
  Assert.assertNotNull(event);
  Assert.assertEquals("Channel contained our event", "Hello avro",
      new String(event.getBody()));
  transaction.commit();
  transaction.close();

  logger.debug("Round trip event:{}", event);

  source.stop();
  Assert.assertTrue("Reached stop or error",
      LifecycleController.waitForOneOf(source, LifecycleState.STOP_OR_ERROR));
  Assert.assertEquals("Server is stopped", LifecycleState.STOP,
      source.getLifecycleState());
}
 
Example #9
Source File: TestAvroSource.java    From mt-flume with Apache License 2.0 4 votes vote down vote up
@Test
public void testSslRequest() throws InterruptedException, IOException {
  boolean bound = false;

  for (int i = 0; i < 10 && !bound; i++) {
    try {
      Context context = new Context();

      context.put("port", String.valueOf(selectedPort = 41414 + i));
      context.put("bind", "0.0.0.0");
      context.put("ssl", "true");
      context.put("keystore", "src/test/resources/server.p12");
      context.put("keystore-password", "password");
      context.put("keystore-type", "PKCS12");

      Configurables.configure(source, context);

      source.start();
      bound = true;
    } catch (ChannelException e) {
      /*
       * NB: This assume we're using the Netty server under the hood and the
       * failure is to bind. Yucky.
       */
      Thread.sleep(100);
    }
  }

  Assert
      .assertTrue("Reached start or error", LifecycleController.waitForOneOf(
          source, LifecycleState.START_OR_ERROR));
  Assert.assertEquals("Server is started", LifecycleState.START,
      source.getLifecycleState());

  AvroSourceProtocol client = SpecificRequestor.getClient(
      AvroSourceProtocol.class, new NettyTransceiver(new InetSocketAddress(
      selectedPort), new SSLChannelFactory()));

  AvroFlumeEvent avroEvent = new AvroFlumeEvent();

  avroEvent.setHeaders(new HashMap<CharSequence, CharSequence>());
  avroEvent.setBody(ByteBuffer.wrap("Hello avro ssl".getBytes()));

  Status status = client.append(avroEvent);

  Assert.assertEquals(Status.OK, status);

  Transaction transaction = channel.getTransaction();
  transaction.begin();

  Event event = channel.take();
  Assert.assertNotNull(event);
  Assert.assertEquals("Channel contained our event", "Hello avro ssl",
      new String(event.getBody()));
  transaction.commit();
  transaction.close();

  logger.debug("Round trip event:{}", event);

  source.stop();
  Assert.assertTrue("Reached stop or error",
      LifecycleController.waitForOneOf(source, LifecycleState.STOP_OR_ERROR));
  Assert.assertEquals("Server is stopped", LifecycleState.STOP,
      source.getLifecycleState());
}
 
Example #10
Source File: TestLegacyAvroSource.java    From mt-flume with Apache License 2.0 4 votes vote down vote up
@Test
public void testRequest() throws InterruptedException, IOException {
  boolean bound = false;
  int i;

  for (i = 0; i < 100 && !bound; i++) {
    try {
      Context context = new Context();

      context.put("port", String.valueOf(selectedPort = 41414 + i));
      context.put("host", "0.0.0.0");

      Configurables.configure(source, context);

      source.start();
      bound = true;
    } catch (ChannelException e) {
      // Assume port in use, try another one
    }
  }

  Assert
      .assertTrue("Reached start or error", LifecycleController.waitForOneOf(
          source, LifecycleState.START_OR_ERROR));
  Assert.assertEquals("Server is started", LifecycleState.START,
      source.getLifecycleState());

  // setup a requester, to send a flume OG event
  URL url = new URL("http", "0.0.0.0", selectedPort, "/");
  Transceiver http = new HttpTransceiver(url);
  FlumeOGEventAvroServer client = SpecificRequestor.getClient(
      FlumeOGEventAvroServer.class, http);

  AvroFlumeOGEvent avroEvent =  AvroFlumeOGEvent.newBuilder().setHost("foo").
      setPriority(Priority.INFO).setNanos(0).setTimestamp(1).
      setFields(new HashMap<CharSequence, ByteBuffer> ()).
      setBody(ByteBuffer.wrap("foo".getBytes())).build();

  client.append(avroEvent);

  // check if the even has arrived in the channel through OG avro source
  Transaction transaction = channel.getTransaction();
  transaction.begin();

  Event event = channel.take();
  Assert.assertNotNull(event);
  Assert.assertEquals("Channel contained our event", "foo",
      new String(event.getBody()));
  transaction.commit();
  transaction.close();

  source.stop();

  Assert.assertTrue("Reached stop or error",
      LifecycleController.waitForOneOf(source, LifecycleState.STOP_OR_ERROR));
  Assert.assertEquals("Server is stopped", LifecycleState.STOP,
      source.getLifecycleState());
}