本文整理汇总了Java中org.apache.avro.ipc.Server.start方法的典型用法代码示例。如果您正苦于以下问题:Java Server.start方法的具体用法?Java Server.start怎么用?Java Server.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.ipc.Server
的用法示例。
在下文中一共展示了Server.start方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLifecycle
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
@Test
public void testLifecycle() throws InterruptedException,
InstantiationException, IllegalAccessException {
setUp();
Server server = createServer(new MockAvroServer());
server.start();
sink.start();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.START_OR_ERROR, 5000));
sink.stop();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.STOP_OR_ERROR, 5000));
server.close();
}
示例2: startTestFlumeServer
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
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;
}
示例3: doExport
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
@Override
protected <T> Runnable doExport(T impl, Class<T> type, URL url)
throws JahhanException {
log.info("impl => " + impl.getClass());
log.info("type => " + type.getName());
log.info("url => " + url);
final Server server = new NettyServer(new ReflectResponder(type, impl),
new InetSocketAddress(url.getHost(), url.getPort()));
server.start();
log.info("Start Avro Server");
return new Runnable() {
public void run() {
try {
log.info("Close Avro Server");
server.close();
} catch (Throwable e) {
log.warn(e.getMessage(), e);
}
}
};
}
示例4: testProcess
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
@Test
public void testProcess() throws InterruptedException,
EventDeliveryException, InstantiationException, IllegalAccessException {
setUp();
Event event = EventBuilder.withBody("test event 1", Charsets.UTF_8);
Server server = createServer(new MockAvroServer());
server.start();
sink.start();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.START_OR_ERROR, 5000));
Transaction transaction = channel.getTransaction();
transaction.begin();
for (int i = 0; i < 10; i++) {
channel.put(event);
}
transaction.commit();
transaction.close();
for (int i = 0; i < 5; i++) {
Sink.Status status = sink.process();
Assert.assertEquals(Sink.Status.READY, status);
}
Assert.assertEquals(Sink.Status.BACKOFF, sink.process());
sink.stop();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.STOP_OR_ERROR, 5000));
server.close();
}
示例5: MemberNettyRPCDynBuilderServer
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
/**
* 服务端支持的网络通讯协议有:NettyServer、SocketServer、HttpServer
* 采用Netty方式调用
*
* @throws IOException
* @throws InterruptedException
*/
public void MemberNettyRPCDynBuilderServer() throws IOException, InterruptedException {
// 1.进行业务处理
GenericResponder gr = bussinessDeal();
// 2.开启一个Netty服务端,进行等待客户端的连接
Server server = new NettyServer(gr, new InetSocketAddress(60090));
server.start();
System.out.println("Dyn Builder PRC Start Complete.");
server.join();
}
示例6: MemberHttpRPCDynBuilderServer
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
/**
* 服务端支持的网络通讯协议有:NettyServer、SocketServer、HttpServer
* 采用HTTPSERVER方式调用
*
* @throws IOException
* @throws InterruptedException
*/
public void MemberHttpRPCDynBuilderServer() throws IOException, InterruptedException {
// 1.进行业务处理
GenericResponder gr = bussinessDeal();
// 2.开启一个HTTP服务端,进行等待客户端的连接
Server server = new HttpServer(gr, 60090);
server.start();
System.out.println("Dyn Builder PRC Start Complete.");
server.join();
}
示例7: MemberNettyRPCToolsBuilderServer
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
/**
* Java工具生成协议代码方式:java -jar E:\avro\avro-tools-1.7.7.jar compile protocol E:\avro\Members.avpr E:\avro
* 功能和动态调用方式一致
* @throws InterruptedException
*/
public void MemberNettyRPCToolsBuilderServer() throws InterruptedException{
//1.构造接口和实现类的映射相应对象,MemberIFaceImpl该类为具体的业务实现类
SpecificResponder responder=new SpecificResponder(MemberIFace.class, new MemberIFaceImpl());
//2.Netty启动RPC服务
Server server=new NettyServer(responder, new InetSocketAddress(60090));
server.start();
System.out.println("Tools Builder PRC Start Complete.");
server.join();
}
示例8: testFailedConnect
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
@Test
public void testFailedConnect() throws InterruptedException,
EventDeliveryException, InstantiationException, IllegalAccessException {
setUp();
Event event = EventBuilder.withBody("test event 1",
Charset.forName("UTF8"));
Server server = createServer(new MockAvroServer());
server.start();
sink.start();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.START_OR_ERROR, 5000));
Thread.sleep(500L); // let socket startup
server.close();
Thread.sleep(500L); // sleep a little to allow close occur
Transaction transaction = channel.getTransaction();
transaction.begin();
for (int i = 0; i < 10; i++) {
channel.put(event);
}
transaction.commit();
transaction.close();
for (int i = 0; i < 5; i++) {
boolean threwException = false;
try {
sink.process();
} catch (EventDeliveryException e) {
threwException = true;
}
Assert.assertTrue("Must throw EventDeliveryException if disconnected",
threwException);
}
server = createServer(new MockAvroServer());
server.start();
for (int i = 0; i < 5; i++) {
Sink.Status status = sink.process();
Assert.assertEquals(Sink.Status.READY, status);
}
Assert.assertEquals(Sink.Status.BACKOFF, sink.process());
sink.stop();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.STOP_OR_ERROR, 5000));
server.close();
}
示例9: testReset
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
@Test
public void testReset() throws Exception {
setUp();
Server server = createServer(new MockAvroServer());
server.start();
Context context = new Context();
context.put("hostname", hostname);
context.put("port", String.valueOf(port));
context.put("batch-size", String.valueOf(2));
context.put("connect-timeout", String.valueOf(2000L));
context.put("request-timeout", String.valueOf(3000L));
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();
t.close();
sink.process();
// Make sure they are not the same object, connection should be reset
Assert.assertFalse(firstClient == sink.getUnderlyingClient());
sink.stop();
context.put("hostname", hostname);
context.put("port", String.valueOf(port));
context.put("batch-size", String.valueOf(2));
context.put("connect-timeout", String.valueOf(2000L));
context.put("request-timeout", String.valueOf(3000L));
context.put("reset-connection-interval", String.valueOf("0"));
sink.setChannel(channel);
Configurables.configure(sink, context);
sink.start();
firstClient = sink.getUnderlyingClient();
Thread.sleep(6000);
// Make sure they are the same object, since connection should not be reset
Assert.assertTrue(firstClient == sink.getUnderlyingClient());
sink.stop();
context.clear();
context.put("hostname", hostname);
context.put("port", String.valueOf(port));
context.put("batch-size", String.valueOf(2));
context.put("connect-timeout", String.valueOf(2000L));
context.put("request-timeout", String.valueOf(3000L));
sink.setChannel(channel);
Configurables.configure(sink, context);
sink.start();
firstClient = sink.getUnderlyingClient();
Thread.sleep(6000);
// Make sure they are the same object, since connection should not be reset
Assert.assertTrue(firstClient == sink.getUnderlyingClient());
sink.stop();
server.close();
}
示例10: testSslProcess
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
@Test
public void testSslProcess() throws InterruptedException,
EventDeliveryException, InstantiationException, IllegalAccessException {
setUp();
Event event = EventBuilder.withBody("test event 1", Charsets.UTF_8);
Server server = createSslServer(new MockAvroServer());
server.start();
Context context = new Context();
context.put("hostname", hostname);
context.put("port", String.valueOf(port));
context.put("ssl", String.valueOf(true));
context.put("trust-all-certs", String.valueOf(true));
context.put("batch-size", String.valueOf(2));
context.put("connect-timeout", String.valueOf(2000L));
context.put("request-timeout", String.valueOf(3000L));
Configurables.configure(sink, context);
sink.start();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.START_OR_ERROR, 5000));
Transaction transaction = channel.getTransaction();
transaction.begin();
for (int i = 0; i < 10; i++) {
channel.put(event);
}
transaction.commit();
transaction.close();
for (int i = 0; i < 5; i++) {
Sink.Status status = sink.process();
Assert.assertEquals(Sink.Status.READY, status);
}
Assert.assertEquals(Sink.Status.BACKOFF, sink.process());
sink.stop();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.STOP_OR_ERROR, 5000));
server.close();
}
示例11: testSslProcessWithTrustStore
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
@Test
public void testSslProcessWithTrustStore() throws InterruptedException,
EventDeliveryException, InstantiationException, IllegalAccessException {
setUp();
Event event = EventBuilder.withBody("test event 1", Charsets.UTF_8);
Server server = createSslServer(new MockAvroServer());
server.start();
Context context = new Context();
context.put("hostname", hostname);
context.put("port", String.valueOf(port));
context.put("ssl", String.valueOf(true));
context.put("truststore", "src/test/resources/truststore.jks");
context.put("truststore-password", "password");
context.put("batch-size", String.valueOf(2));
context.put("connect-timeout", String.valueOf(2000L));
context.put("request-timeout", String.valueOf(3000L));
Configurables.configure(sink, context);
sink.start();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.START_OR_ERROR, 5000));
Transaction transaction = channel.getTransaction();
transaction.begin();
for (int i = 0; i < 10; i++) {
channel.put(event);
}
transaction.commit();
transaction.close();
for (int i = 0; i < 5; i++) {
Sink.Status status = sink.process();
Assert.assertEquals(Sink.Status.READY, status);
}
Assert.assertEquals(Sink.Status.BACKOFF, sink.process());
sink.stop();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.STOP_OR_ERROR, 5000));
server.close();
}
示例12: testSslSinkWithNonSslServer
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
@Test
public void testSslSinkWithNonSslServer() throws InterruptedException,
EventDeliveryException, InstantiationException, IllegalAccessException {
setUp();
Event event = EventBuilder.withBody("test event 1", Charsets.UTF_8);
Server server = createServer(new MockAvroServer());
server.start();
Context context = new Context();
context.put("hostname", hostname);
context.put("port", String.valueOf(port));
context.put("ssl", String.valueOf(true));
context.put("trust-all-certs", String.valueOf(true));
context.put("batch-size", String.valueOf(2));
context.put("connect-timeout", String.valueOf(2000L));
context.put("request-timeout", String.valueOf(3000L));
Configurables.configure(sink, context);
sink.start();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.START_OR_ERROR, 5000));
Transaction transaction = channel.getTransaction();
transaction.begin();
for (int i = 0; i < 10; i++) {
channel.put(event);
}
transaction.commit();
transaction.close();
boolean failed = false;
try {
for (int i = 0; i < 5; i++) {
sink.process();
failed = true;
}
} catch (EventDeliveryException ex) {
logger.info("Correctly failed to send event", ex);
}
sink.stop();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.STOP_OR_ERROR, 5000));
server.close();
if (failed) {
Assert.fail("SSL-enabled sink successfully connected to a non-SSL-enabled server, that's wrong.");
}
}
示例13: testSslSinkWithNonTrustedCert
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
@Test
public void testSslSinkWithNonTrustedCert()
throws InterruptedException, EventDeliveryException, InstantiationException,
IllegalAccessException {
setUp();
Event event = EventBuilder.withBody("test event 1", Charsets.UTF_8);
Server server = createSslServer(new MockAvroServer());
server.start();
Context context = new Context();
context.put("hostname", hostname);
context.put("port", String.valueOf(port));
context.put("ssl", String.valueOf(true));
context.put("batch-size", String.valueOf(2));
context.put("connect-timeout", String.valueOf(2000L));
context.put("request-timeout", String.valueOf(3000L));
Configurables.configure(sink, context);
sink.start();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.START_OR_ERROR, 5000));
Transaction transaction = channel.getTransaction();
transaction.begin();
for (int i = 0; i < 10; i++) {
channel.put(event);
}
transaction.commit();
transaction.close();
boolean failed = false;
try {
for (int i = 0; i < 5; i++) {
sink.process();
failed = true;
}
} catch (EventDeliveryException ex) {
logger.info("Correctly failed to send event", ex);
}
sink.stop();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.STOP_OR_ERROR, 5000));
server.close();
if (failed) {
Assert.fail("SSL-enabled sink successfully connected to a server with an untrusted certificate when it should have failed");
}
}