Examples of RpcClient


Examples of org.apache.flume.api.RpcClient

    context.put("reset-connection-interval", String.valueOf("5"));

    sink.setChannel(channel);
    Configurables.configure(sink, context);
    sink.start();
    RpcClient firstClient = sink.getUnderlyingClient();
    Thread.sleep(6000);
    Transaction t = channel.getTransaction();
    t.begin();
    channel.put(EventBuilder.withBody("This is a test", Charset.defaultCharset()));
    t.commit();
View Full Code Here

Examples of org.apache.flume.api.RpcClient

  private void run() throws IOException, FlumeException,
      EventDeliveryException {

    BufferedReader reader = null;

    RpcClient rpcClient = RpcClientFactory.getDefaultInstance(hostname, port, BATCH_SIZE);
    try {
      List<Event> eventBuffer = Lists.newArrayList();

      if (fileName != null) {
        reader = new BufferedReader(new FileReader(new File(fileName)));
      } else {
        reader = new BufferedReader(new InputStreamReader(System.in));
      }

      String line;
      long lastCheck = System.currentTimeMillis();
      long sentBytes = 0;

      int batchSize = rpcClient.getBatchSize();
      while ((line = reader.readLine()) != null) {
        // logger.debug("read:{}", line);

        int size = eventBuffer.size();
        if (size == batchSize) {
          rpcClient.appendBatch(eventBuffer);
          eventBuffer.clear();
        }

        Event event = EventBuilder.withBody(line, Charset.forName("UTF8"));
        setHeaders(event);
        eventBuffer.add(event);

        sentBytes += event.getBody().length;
        sent++;

        long now = System.currentTimeMillis();

        if (now >= lastCheck + 5000) {
          logger.debug("Packed {} bytes, {} events", sentBytes, sent);
          lastCheck = now;
        }
      }

      if (!eventBuffer.isEmpty()) {
        rpcClient.appendBatch(eventBuffer);
      }

      logger.debug("Finished");
    } finally {
      if (reader != null) {
        logger.debug("Closing reader");
        reader.close();
      }

      logger.debug("Closing RPC client");
      rpcClient.close();
    }
  }
View Full Code Here

Examples of org.apache.flume.api.RpcClient

     try {

       StagedInstall.getInstance().startAgent(
         "rpccagent", CONFIG_FILE_PRCCLIENT_TEST);
       StagedInstall.waitUntilPortOpens("localhost", 12121, 20000);
       RpcClient client = RpcClientFactory.getDefaultInstance(
           "localhost", 12121);
       String[] text = {"foo", "bar", "xyz", "abc"};
       for (String str : text) {
         client.append(EventBuilder.withBody(str.getBytes()));
       }

       // Stop the agent
       StagedInstall.getInstance().stopAgent();

       // Try sending the event which should fail
       try {
         client.append(EventBuilder.withBody("test".getBytes()));
         Assert.fail("EventDeliveryException expected but not raised");
       } catch (EventDeliveryException ex) {
         System.out.println("Attempting to close client");
         client.close();
       }
     } finally {
       if (StagedInstall.getInstance().isRunning()) {
         StagedInstall.getInstance().stopAgent();
       }
View Full Code Here

Examples of org.apache.flume.api.RpcClient

  }

  @Test
  public void testRpcClient() throws Exception {
    StagedInstall.waitUntilPortOpens("localhost", 12121, 20000);
    RpcClient client = RpcClientFactory.getDefaultInstance("localhost", 12121);
    String[] text = {"foo", "bar", "xyz", "abc"};
    for (String str : text) {
      client.append(EventBuilder.withBody(str.getBytes()));
    }
  }
View Full Code Here

Examples of org.apache.flume.api.RpcClient

    context.put("reset-connection-interval", String.valueOf("5"));

    sink.setChannel(channel);
    Configurables.configure(sink, context);
    sink.start();
    RpcClient firstClient = sink.getUnderlyingClient();
    Thread.sleep(6000);
    // Make sure they are not the same object, connection should be reset
    Assert.assertFalse(firstClient == sink.getUnderlyingClient());
    sink.stop();
View Full Code Here

Examples of org.apache.flume.api.RpcClient

  private void run() throws IOException, FlumeException,
      EventDeliveryException {

    BufferedReader reader = null;

    RpcClient rpcClient = RpcClientFactory.getInstance(hostname, port, BATCH_SIZE);
    try {
      List<Event> eventBuffer = Lists.newArrayList();

      if (fileName != null) {
        reader = new BufferedReader(new FileReader(new File(fileName)));
      } else {
        reader = new BufferedReader(new InputStreamReader(System.in));
      }

      String line;
      long lastCheck = System.currentTimeMillis();
      long sentBytes = 0;

      int batchSize = rpcClient.getBatchSize();
      while ((line = reader.readLine()) != null) {
        // logger.debug("read:{}", line);

        int size = eventBuffer.size();
        if (size == batchSize) {
          rpcClient.appendBatch(eventBuffer);
          eventBuffer.clear();
        }

        Event event = EventBuilder.withBody(line, Charset.forName("UTF8"));
        eventBuffer.add(event);

        sentBytes += event.getBody().length;
        sent++;

        long now = System.currentTimeMillis();

        if (now >= lastCheck + 5000) {
          logger.debug("Packed {} bytes, {} events", sentBytes, sent);
          lastCheck = now;
        }
      }

      if (!eventBuffer.isEmpty()) {
        rpcClient.appendBatch(eventBuffer);
      }

      logger.debug("Finished");
    } finally {
      if (reader != null) {
        logger.debug("Closing reader");
        reader.close();
      }

      logger.debug("Closing RPC client");
      rpcClient.close();
    }
  }
View Full Code Here

Examples of org.apache.flume.api.RpcClient

  private void run() throws IOException, FlumeException,
      EventDeliveryException {

    EventReader reader = null;

    RpcClient rpcClient;
    if (rpcClientPropsFile != null) {
      rpcClient = RpcClientFactory.getInstance(new File(rpcClientPropsFile));
    } else {
      rpcClient = RpcClientFactory.getDefaultInstance(hostname, port,
          BATCH_SIZE);
    }

    try {
      if (fileName != null) {
        reader = new SimpleTextLineEventReader(new FileReader(new File(fileName)));
      } else if (dirName != null) {
        reader = new ReliableSpoolingFileEventReader.Builder()
            .spoolDirectory(new File(dirName)).build();
      } else {
        reader = new SimpleTextLineEventReader(new InputStreamReader(System.in));
      }

      long lastCheck = System.currentTimeMillis();
      long sentBytes = 0;

      int batchSize = rpcClient.getBatchSize();
      List<Event> events;
      while (!(events = reader.readEvents(batchSize)).isEmpty()) {
        for (Event event : events) {
          event.setHeaders(headers);
          sentBytes += event.getBody().length;
          sent++;

          long now = System.currentTimeMillis();
          if (now >= lastCheck + 5000) {
            logger.debug("Packed {} bytes, {} events", sentBytes, sent);
            lastCheck = now;
          }
        }
        rpcClient.appendBatch(events);
        if (reader instanceof ReliableEventReader) {
          ((ReliableEventReader) reader).commit();
        }
      }
      logger.debug("Finished");
    } finally {
      if (reader != null) {
        logger.debug("Closing reader");
        reader.close();
      }

      logger.debug("Closing RPC client");
      rpcClient.close();
    }
  }
View Full Code Here

Examples of org.apache.hadoop.hbase.ipc.RpcClient

      this.batchPool = pool;
      this.managed = managed;
      this.registry = setupRegistry();
      retrieveClusterId();

      this.rpcClient = new RpcClient(this.conf, this.clusterId);

      // Do we publish the status?
      boolean shouldListen = conf.getBoolean(HConstants.STATUS_PUBLISHED,
          HConstants.STATUS_PUBLISHED_DEFAULT);
      Class<? extends ClusterStatusListener.Listener> listenerClass =
View Full Code Here

Examples of org.apache.hadoop.hbase.ipc.RpcClient

     * For tests only.
     * @param rpcClient Client we should use instead.
     * @return Previous rpcClient
     */
    RpcClient setRpcClient(final RpcClient rpcClient) {
      RpcClient oldRpcClient = this.rpcClient;
      this.rpcClient = rpcClient;
      return oldRpcClient;
    }
View Full Code Here

Examples of org.apache.hadoop.hbase.ipc.RpcClient

    // verify the server authenticates us as this token user
    testuser.doAs(new PrivilegedExceptionAction<Object>() {
      public Object run() throws Exception {
        Configuration c = server.getConfiguration();
        RpcClient rpcClient = new RpcClient(c, clusterId.toString());
        ServerName sn =
          new ServerName(server.getAddress().getHostName(), server.getAddress().getPort(),
            System.currentTimeMillis());
        try {
          BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(sn,
            User.getCurrent(), HConstants.DEFAULT_HBASE_RPC_TIMEOUT);
          AuthenticationProtos.AuthenticationService.BlockingInterface stub =
            AuthenticationProtos.AuthenticationService.newBlockingStub(channel);
          AuthenticationProtos.WhoAmIResponse response =
            stub.whoAmI(null, AuthenticationProtos.WhoAmIRequest.getDefaultInstance());
          String myname = response.getUsername();
          assertEquals("testuser", myname);
          String authMethod = response.getAuthMethod();
          assertEquals("TOKEN", authMethod);
        } finally {
          rpcClient.stop();
        }
        return null;
      }
    });
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.