当前位置: 首页>>代码示例>>Java>>正文


Java RpcClientFactory.getDefaultInstance方法代码示例

本文整理汇总了Java中org.apache.flume.api.RpcClientFactory.getDefaultInstance方法的典型用法代码示例。如果您正苦于以下问题:Java RpcClientFactory.getDefaultInstance方法的具体用法?Java RpcClientFactory.getDefaultInstance怎么用?Java RpcClientFactory.getDefaultInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.flume.api.RpcClientFactory的用法示例。


在下文中一共展示了RpcClientFactory.getDefaultInstance方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startClient

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
/**
 * Create / reconnect Flume RPC client
 */
private void startClient() {
  // If current client is inactive, close it
  if (flumeClient != null && !flumeClient.isActive()) {
    flumeClient.close();
    flumeClient = null;
  }
  // Create client if needed
  if (flumeClient == null) {
    try {
      flumeClient = RpcClientFactory.getDefaultInstance(flumeHostName, flumePort, maxSpanBatchSize);
    } catch (FlumeException e) {
      LOG.warn("Failed to create Flume RPC Client. " + e.getMessage());
    }
  }
}
 
开发者ID:apache,项目名称:incubator-htrace,代码行数:19,代码来源:FlumeSpanReceiver.java

示例2: testFailure

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
@Test
public void testFailure() throws Exception {
  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();
    }
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:32,代码来源:TestRpcClientCommunicationFailure.java

示例3: testRpcClient

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
@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()));
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:10,代码来源:TestRpcClient.java

示例4: init

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
/**
 * Initializes the connection to Apache Flume.
 *
 * @param hostname
 *            The host
 * @param port
 *            The port.
 */
public void init(String hostname, int port) {
    // Setup the RPC connection
    this.hostname = hostname;
    this.port = port;
    int initCounter = 0;
    while (true) {
        if (initCounter >= 90) {
            throw new RuntimeException("Cannot establish connection with" + port + " at "
                    + host);
        }
        try {
            this.client = RpcClientFactory.getDefaultInstance(hostname, port);
        } catch (FlumeException e) {
            // Wait one second if the connection failed before the next
            // try
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e1) {
                if (LOG.isErrorEnabled()) {
                    LOG.error("Interrupted while trying to connect {} at {}", port, host);
                }
            }
        }
        if (client != null) {
            break;
        }
        initCounter++;
    }
    initDone = true;
}
 
开发者ID:apache,项目名称:bahir-flink,代码行数:39,代码来源:FlumeSink.java

示例5: sendDataToFlume

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
/**
 * Sends byte arrays as {@link Event} series to Apache Flume.
 *
 * @param data
 *            The byte array to send to Apache FLume
 */
public void sendDataToFlume(byte[] data) {
    Event event = EventBuilder.withBody(data);

    try {
        client.append(event);

    } catch (EventDeliveryException e) {
        // clean up and recreate the client
        client.close();
        client = null;
        client = RpcClientFactory.getDefaultInstance(hostname, port);
    }
}
 
开发者ID:apache,项目名称:bahir-flink,代码行数:20,代码来源:FlumeSink.java

示例6: init

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
/**
 * Initializes the connection to Apache Flume.
 * 
 * @param hostname
 *            The host
 * @param port
 *            The port.
 */
public void init(String hostname, int port) {
	// Setup the RPC connection
	this.hostname = hostname;
	this.port = port;
	int initCounter = 0;
	while (true) {
		if (initCounter >= 90) {
			throw new RuntimeException("Cannot establish connection with" + port + " at "
					+ host);
		}
		try {
			this.client = RpcClientFactory.getDefaultInstance(hostname, port);
		} catch (FlumeException e) {
			// Wait one second if the connection failed before the next
			// try
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e1) {
				if (LOG.isErrorEnabled()) {
					LOG.error("Interrupted while trying to connect {} at {}", port, host);
				}
			}
		}
		if (client != null) {
			break;
		}
		initCounter++;
	}
	initDone = true;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:39,代码来源:FlumeSink.java

示例7: sendDataToFlume

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
/**
 * Sends byte arrays as {@link Event} series to Apache Flume.
 * 
 * @param data
 *            The byte array to send to Apache FLume
 */
public void sendDataToFlume(byte[] data) {
	Event event = EventBuilder.withBody(data);

	try {
		client.append(event);

	} catch (EventDeliveryException e) {
		// clean up and recreate the client
		client.close();
		client = null;
		client = RpcClientFactory.getDefaultInstance(hostname, port);
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:20,代码来源:FlumeSink.java

示例8: sendData

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
public void sendData(String data){
    Event event = EventBuilder.withBody(data.getBytes());

    try {
        rpcClient.append(event);
    } catch (EventDeliveryException e) {
        e.printStackTrace();
        rpcClient.close();
        rpcClient = RpcClientFactory.getDefaultInstance(this.hostName, this.port);
    }

}
 
开发者ID:srecon,项目名称:ignite-book-code-samples,代码行数:13,代码来源:RpcEventGenerator.java

示例9: AvroAsyncRpcClient

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
/**
 * Create new instance of <code>AvroAsyncRpcClient</code>.
 *
 * @param hostname        the RPC hostname, use it to create RPC client
 * @param port            the RPC port, use it to create RPC client
 * @param numberOfThreads is number of client's threads
 */
public AvroAsyncRpcClient(String hostname, Integer port, int numberOfThreads) {
  int numberOfClientThreads = numberOfThreads;

  clientQueue = new ArrayBlockingQueue<RpcClient>(numberOfClientThreads);

  for (int i = 0; i < numberOfClientThreads; i++) {
    RpcClient client = RpcClientFactory.getDefaultInstance(hostname, port);
    clientQueue.add(client);
  }

  LOG.info("Number of Threads:" + numberOfClientThreads);
  executorService = MoreExecutors
      .listeningDecorator(Executors.newFixedThreadPool(numberOfClientThreads));
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:22,代码来源:AvroAsyncRpcClient.java

示例10: init

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
/**
 * Initializes the connection to Apache Flume.
 * 
 * @param hostname
 *            The host
 * @param port
 *            The port.
 */
public void init(String hostname, int port) {
	// Setup the RPC connection
	this.hostname = hostname;
	this.port = port;
	int initCounter = 0;
	while (true) {
		if (initCounter >= 90) {
			throw new RuntimeException("Cannot establish connection with" + port + " at " + host);
		}
		try {
			this.client = RpcClientFactory.getDefaultInstance(hostname, port);
		} catch (FlumeException e) {
			// Wait one second if the connection failed before the next
			// try
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e1) {
				if (LOG.isErrorEnabled()) {
					LOG.error("Interrupted while trying to connect {} at {}", port, host);
				}
			}
		}
		if (client != null) {
			break;
		}
		initCounter++;
	}
	initDone = true;
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:38,代码来源:FlumeSink.java

示例11: activateOptions

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
/**
 * Activate the options set using <tt>setPort()</tt>
 * and <tt>setHostname()</tt>
 * @throws FlumeException if the <tt>hostname</tt> and
 *  <tt>port</tt> combination is invalid.
 */
@Override
public void activateOptions() throws FlumeException{
  try {
    rpcClient = RpcClientFactory.getDefaultInstance(hostname, port);
  } catch (FlumeException e) {
    String errormsg = "RPC client creation failed! " +
        e.getMessage();
    LogLog.error(errormsg);
    throw e;
  }
  if(layout != null) {
    layout.activateOptions();
  }
}
 
开发者ID:cloudera,项目名称:cdk,代码行数:21,代码来源:Log4jAppender.java

示例12: run

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
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();
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:57,代码来源:AvroCLIClient.java

示例13: init

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
public void init(String hostname, int port) {
	// Setup the RPC connection
	this.client = RpcClientFactory.getDefaultInstance(hostname, port);
}
 
开发者ID:alokawi,项目名称:spark-cassandra-poc,代码行数:5,代码来源:FlumeDataWriter.java

示例14: RpcEventGenerator

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
public RpcEventGenerator(String hostName, int port) {
    this.hostName = hostName;
    this.port = port;
    this.rpcClient = RpcClientFactory.getDefaultInstance(hostName, port);
}
 
开发者ID:srecon,项目名称:ignite-book-code-samples,代码行数:6,代码来源:RpcEventGenerator.java


注:本文中的org.apache.flume.api.RpcClientFactory.getDefaultInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。