org.apache.avro.ipc.Transceiver Java Examples

The following examples show how to use org.apache.avro.ipc.Transceiver. 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: AbstractRequestInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
    if (objInst.getSkyWalkingDynamicField() == null) {
        Requestor requestor = (Requestor) objInst;
        requestor.addRPCPlugin(new SWClientRPCPlugin());

        Protocol protocol = (Protocol) allArguments[0];
        Transceiver transceiver = (Transceiver) allArguments[1];
        try {
            objInst.setSkyWalkingDynamicField(new AvroInstance(protocol.getNamespace() + "." + protocol.getName() + ".", transceiver
                .getRemoteName()));
        } catch (IOException e) {
            objInst.setSkyWalkingDynamicField(new AvroInstance("Undefined", "Undefined"));
            logger.error("Failed to get Avro Remote Client Information.", e);
        }
    }
}
 
Example #2
Source File: ExpressionCallTest.java    From depends with MIT License 4 votes vote down vote up
public GenericRequestor(Protocol protocol, Transceiver transceiver)
  throws IOException {
  this(protocol, transceiver, GenericData.get());
}
 
Example #3
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());
}