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


Java Client类代码示例

本文整理汇总了Java中io.advantageous.qbit.client.Client的典型用法代码示例。如果您正苦于以下问题:Java Client类的具体用法?Java Client怎么用?Java Client使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getRemoteByName

import io.advantageous.qbit.client.Client; //导入依赖的package包/类
public static <T> T getRemoteByName(final URI address, final Class<T> clazz, final String name) {

        /* Start QBit client for WebSocket calls. */
        final Client client = ClientBuilder.clientBuilder()
                .setHost(address.getHost())
                .setPort(address.getPort())
                .setUri(address.getPath())
                .build();
        try {
            /* Create a proxy to the service. */
            final T clientProxy = client.createProxy(clazz, name);
            client.start();
            return clientProxy;
        } catch (Exception ex) {
            try {
                client.stop();
            } catch (Exception ex2) {
                //don't log, we are cleaning up.
            }
            /* Wrong place to handle the exception so just rethrow it. */
            throw new IllegalStateException(ex);
        }
    }
 
开发者ID:advantageous,项目名称:qbit,代码行数:24,代码来源:RemoteFactoryUtil.java

示例2: runCalls

import io.advantageous.qbit.client.Client; //导入依赖的package包/类
/** Each client will run this
     *
     * @param numCalls number of times to make calls
     * @param count holds the total count
     */
    private static void runCalls(final int numCalls, final AtomicInteger count) {
        final Client client = clientBuilder().setUri("/").build();

        final TradeServiceAsync tradeService = client.createProxy(TradeServiceAsync.class, "t");

        client.startClient();

        for (int call=0; call < numCalls; call++) {
            tradeService.a(response -> {
                if (response) {
                    count.incrementAndGet();
                    //System.out.println("count " + count.get());
                }
            }, new Trade("IBM", 1));

//            tradeService.t2(new Trade("IBM", 1))
//                    .then(response -> {
//                                if (response) {
//                                    count.incrementAndGet();
//                                }
//                            }
//                    )
//                    .catchError(Throwable::printStackTrace)
//                    .invoke();

            if (call % 100 == 0) {
                if (call > count.get() - 2000) {
                    Sys.sleep(1);
                }
                //flushServiceProxy(tradeService);
            }

        }

        flushServiceProxy(tradeService);
    }
 
开发者ID:advantageous,项目名称:qbit-extensions,代码行数:42,代码来源:TradeServiceLoadTestWebSocket.java

示例3: addEventConnector

import io.advantageous.qbit.client.Client; //导入依赖的package包/类
private void addEventConnector(final String newHost, final int newPort) {

        if (info) logger.info(Str.sputs("Adding new event connector for",
                eventBusName, "host",
                newHost, "port", newPort));

        /* A client replicator */
        final EventBusReplicationClientBuilder clientReplicatorBuilder = eventBusReplicationClientBuilder();
        clientReplicatorBuilder.setName(this.eventBusName);
        clientReplicatorBuilder.clientBuilder().setPort(newPort).setHost(newHost);
        final Client client = clientReplicatorBuilder.build();
        final EventConnector eventConnector = clientReplicatorBuilder.build(client);
        client.start();
        eventConnectorHub.add(eventConnector);
    }
 
开发者ID:advantageous,项目名称:qbit-extensions,代码行数:16,代码来源:EventBusCluster.java

示例4: createClient

import io.advantageous.qbit.client.Client; //导入依赖的package包/类
@Override
public Client createClient(final String uri,
                           final HttpClient httpClient,
                           final int requestBatchSize,
                           final BeforeMethodSent beforeMethodSent) {
    return FactorySPI.getClientFactory().create(uri, httpClient, requestBatchSize, beforeMethodSent);
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:8,代码来源:BoonQBitFactory.java

示例5: create

import io.advantageous.qbit.client.Client; //导入依赖的package包/类
@Override
public Client create(final String uri,
                     final HttpClient httpClient,
                     final int requestBatchSize,
                     final BeforeMethodSent beforeMethodSent) {
    return new BoonClient(uri, httpClient, requestBatchSize, beforeMethodSent);
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:8,代码来源:BoonClientFactory.java

示例6: main

import io.advantageous.qbit.client.Client; //导入依赖的package包/类
public static void main(final String... args) throws Exception {

        final ClientBuilder clientBuilder = ClientBuilder.clientBuilder();
        final Client client = clientBuilder.setHost("localhost")
                .setPort(8080).setUri("/echo")
                .build().startClient();

        final EchoAsync echoClient = client.createProxy(EchoAsync.class, "echo");


        for (int index = 0; index < 100; index++) {
            echoClient.echo(s -> System.out.println(s), "index" + index);

        }

        ServiceProxyUtils.flushServiceProxy(echoClient);

    }
 
开发者ID:advantageous,项目名称:qbit-extensions,代码行数:19,代码来源:EchoClientMain.java

示例7: main

import io.advantageous.qbit.client.Client; //导入依赖的package包/类
public static void main(final String... args) throws Exception {

        final ClientBuilder clientBuilder = ClientBuilder.clientBuilder();
        final Client client = clientBuilder.setServiceDiscovery(new ServiceDiscoveryMock(), "echo")
                .setUri("/echo").setProtocolBatchSize(20).build().startClient();

        final EchoAsync echoClient = client.createProxy(EchoAsync.class, "echo");


        for (int index = 0; index < 100000; index++) {
            echoClient.echo(s -> System.out.println(s), "index" + index);

            if (index % 20 == 0) {
                ServiceProxyUtils.flushServiceProxy(echoClient);
            }

        }

        ServiceProxyUtils.flushServiceProxy(echoClient);

    }
 
开发者ID:advantageous,项目名称:qbit-extensions,代码行数:22,代码来源:EchoClientMainWithServiceDiscovery.java

示例8: testWithClient

import io.advantageous.qbit.client.Client; //导入依赖的package包/类
@Test //Works
public void testWithClient() {


    int port = PortUtils.findOpenPortStartAt(9999);
    final ServiceEndpointServer serviceEndpointServer =
            EndpointServerBuilder.endpointServerBuilder().setPort(port)
                    .addService("foo", new FeedServiceImpl()).build().startServerAndWait();


    final Client client = ClientBuilder.clientBuilder().setPort(port).build().startClient();

    final FeedService feedService = client.createProxy(FeedService.class, "foo");


    final List<FeedMeta> feedMetas = feedService.listFeeds().blockingGet(Duration.ofSeconds(30));


    assertNotNull(feedMetas);
    assertEquals(1, feedMetas.size());

    assertEquals("Hello", feedMetas.get(0).name);

    serviceEndpointServer.stop();
    client.stop();
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:27,代码来源:Bug746.java

示例9: createClient

import io.advantageous.qbit.client.Client; //导入依赖的package包/类
default Client createClient(String uri,
                            HttpClient httpClient,
                            int requestBatchSize,
                            BeforeMethodSent beforeMethodSent) {
    throw new UnsupportedOperationException();
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:7,代码来源:Factory.java

示例10: create

import io.advantageous.qbit.client.Client; //导入依赖的package包/类
Client create(String uri,
HttpClient httpClient,
int requestBatchSize,
final BeforeMethodSent beforeMethodSent);
 
开发者ID:advantageous,项目名称:qbit,代码行数:5,代码来源:ClientFactory.java

示例11: testDisconnect

import io.advantageous.qbit.client.Client; //导入依赖的package包/类
@Test
public void testDisconnect() {
    final int port = PortUtils.findOpenPortStartAt(7777);

    final ServiceEndpointServer serviceEndpointServer = EndpointServerBuilder.endpointServerBuilder()
            .setPort(port).setHost("localhost")
            .addService(new EmployeeServiceImpl()).build().startServerAndWait();

    final Client client = ClientBuilder.clientBuilder().setPort(port).setHost("localhost").build().startClient();

    final EmployeeServiceClient employeeService = client.createProxy(EmployeeServiceClient.class, "employeeserviceimpl");

    Promise<Employee> promise = Promises.blockingPromise();

    employeeService.addEmployee(new Employee("rick")).asHandler().invokeWithPromise(promise.asHandler());

    ServiceProxyUtils.flushServiceProxy(employeeService);
    assertTrue(promise.asHandler().success());

    serviceEndpointServer.stop();

    promise = Promises.blockingPromise();

    employeeService.addEmployee(new Employee("rick")).asHandler().invokeWithPromise(promise.asHandler());

    assertTrue(promise.asHandler().failure());

    assertTrue(promise.asHandler().cause() instanceof ConnectException);

    client.stop();

}
 
开发者ID:advantageous,项目名称:qbit,代码行数:33,代码来源:WebSocketProxy.java

示例12: testSendGenericList

import io.advantageous.qbit.client.Client; //导入依赖的package包/类
@Test
public void testSendGenericList() {

    final int port = PortUtils.findOpenPortStartAt(7777);

    final ServiceEndpointServer serviceEndpointServer = EndpointServerBuilder.endpointServerBuilder()
            .setPort(port).setHost("localhost")
            .addService(new EmployeeServiceImpl()).build().startServerAndWait();

    final Client client = ClientBuilder.clientBuilder().setPort(port).setHost("localhost").build().startClient();

    final EmployeeServiceClient employeeService = client.createProxy(EmployeeServiceClient.class, "employeeserviceimpl");

    Promise<Boolean> promise = Promises.blockingPromise();

    employeeService.addEmployees(Arrays.asList(new Employee("rick"))).asHandler().invokeWithPromise(promise.asHandler());

    ServiceProxyUtils.flushServiceProxy(employeeService);

    boolean success = promise.asHandler().success();

    if (!success) {
        promise.asHandler().cause().printStackTrace();
    }
    assertTrue(success);


    serviceEndpointServer.stop();
    client.stop();

}
 
开发者ID:advantageous,项目名称:qbit,代码行数:32,代码来源:WebSocketProxy.java

示例13: test

import io.advantageous.qbit.client.Client; //导入依赖的package包/类
@Test
public void test() throws Exception {


    final int port = PortUtils.findOpenPortStartAt(7777);
    final ServiceEndpointServer serviceEndpointServer = EndpointServerBuilder.endpointServerBuilder()
            .setPort(port).setHost("localhost")
            .addService(new EmployeeServiceImpl()).build().startServerAndWait();

    final Client client = ClientBuilder.clientBuilder().setPort(port).setHost("localhost").build().startClient();

    final EmployeeService employeeService = client.createProxy(EmployeeService.class, "employeeserviceimpl");

    ServiceProxyUtils.flushServiceProxy(employeeService);


    AtomicLong counter = new AtomicLong();
    final CountDownLatch latch = new CountDownLatch(20);

    for (int index = 0; index < 20; index++) {
        final AtomicReference<Employee> ref = new AtomicReference<>();
        employeeService.addEmployee(employee -> {
            ref.set(employee);
            System.out.println(ref.get());
            counter.incrementAndGet();
            latch.countDown();
        }, new Employee("rick"));

    }


    latch.await(2, TimeUnit.SECONDS);
    assertEquals(20, counter.get());


    serviceEndpointServer.stop();
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:38,代码来源:WebSocketProxy.java

示例14: main

import io.advantageous.qbit.client.Client; //导入依赖的package包/类
public static void main(String... args) throws Exception {

        Client client = new ClientBuilder().setPort(9998)
                .setAutoFlush(true).setFlushInterval(50)
                .setProtocolBatchSize(50).build();

        PingService pingService = client.createProxy(PingService.class, "ping");

        client.start();

        pingService.ping(s -> puts("FROM SERVER", s));
    }
 
开发者ID:advantageous,项目名称:qbit,代码行数:13,代码来源:ServiceServerClient.java

示例15: main

import io.advantageous.qbit.client.Client; //导入依赖的package包/类
public static void main(String... args) {

        String host = "localhost";

        int port = 8080;


        /* Create a client object.
        * A client object connects to a ServiceEndpointServer so
        * you can invoke a service over WebSocket.
        */
        final Client client = new ClientBuilder()
                .setPort(port).setHost(host).setPollTime(10)
                .setAutoFlush(true).setFlushInterval(50)
                .setRequestBatchSize(50)
                .setProtocolBatchSize(50).build();

        client.start();

        final TodoServiceClientInterface todoService =
                client.createProxy(TodoServiceClientInterface.class, "todoService");



        todoService.add(new TodoItem("Buy Milk"));
        todoService.add(new TodoItem("Buy Hot dogs"));
        todoService.list(todoItems -> { //LAMBDA EXPRESSION Java 8

            for (TodoItem item : todoItems) {
                System.out.println("TODO ITEM " +
                        item.getDescription() + " " +
                        item.getName() + " " +
                        item.getDue());
            }
        });


        Sys.sleep(1000);


    }
 
开发者ID:advantageous,项目名称:qbit-extensions,代码行数:42,代码来源:TodoClientMain.java


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