當前位置: 首頁>>代碼示例>>Java>>正文


Java ServiceBundleBuilder類代碼示例

本文整理匯總了Java中io.advantageous.qbit.service.ServiceBundleBuilder的典型用法代碼示例。如果您正苦於以下問題:Java ServiceBundleBuilder類的具體用法?Java ServiceBundleBuilder怎麽用?Java ServiceBundleBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ServiceBundleBuilder類屬於io.advantageous.qbit.service包,在下文中一共展示了ServiceBundleBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setup

import io.advantageous.qbit.service.ServiceBundleBuilder; //導入依賴的package包/類
@Before
public void setup() {
    super.setupLatch();
    final Factory factory = QBit.factory();
    final ProtocolParser protocolParser = factory.createProtocolParser();
    final ProtocolEncoder encoder = factory.createEncoder();

    final ServiceBundle serviceBundle = new ServiceBundleBuilder().setAddress("/services").build();
    final JsonMapper mapper = factory.createJsonMapper();

    httpServer = new HttpServerMock();
    serviceServerImpl = new ServiceEndpointServerImpl(httpServer, encoder, protocolParser, serviceBundle, mapper, 1, 100, 30, 10, null, "",
            "", null, null, "localhost", 8080, 0, null, null, 50, 2, 2);

    callMeCounter = 0;
    responseCounter = 0;
    serviceServerImpl.initServices(new ServiceMockObject());
    serviceServerImpl.start();

    Sys.sleep(500);

}
 
開發者ID:advantageous,項目名稱:qbit,代碼行數:23,代碼來源:ServiceEndpointServerImplTest.java

示例2: setUp

import io.advantageous.qbit.service.ServiceBundleBuilder; //導入依賴的package包/類
@Before
public void setUp() throws Exception {

    setupLatch();
    sum = new AtomicInteger();

    client = new BoonClientFactory().create("/services", new HttpClientMock(), 10, new BeforeMethodSent() {
    });

    client.start();
    serviceBundle = new ServiceBundleBuilder().setAddress("/services").buildAndStart();
    serviceBundle.addService(new ServiceMock());
    sum.set(0);
    serviceBundle.startReturnHandlerProcessor(item -> response = item);
    Sys.sleep(1000);
}
 
開發者ID:advantageous,項目名稱:qbit,代碼行數:17,代碼來源:BoonClientIntegrationTest.java

示例3: before

import io.advantageous.qbit.service.ServiceBundleBuilder; //導入依賴的package包/類
@Before
public void before() {

    factory = QBit.factory();

    final ServiceBundle bundle = new ServiceBundleBuilder().setAddress("/foo").buildAndStart();
    serviceBundle = bundle;
    serviceBundleImpl = (ServiceBundleImpl) bundle;
    adderService = new AdderService();
    callCount = 0;

}
 
開發者ID:advantageous,項目名稱:qbit,代碼行數:13,代碼來源:ServiceBundleImplTest.java

示例4: testManager

import io.advantageous.qbit.service.ServiceBundleBuilder; //導入依賴的package包/類
@Test
public void testManager() throws Exception {

    /** Create service bundle . */
    final ServiceBundleBuilder serviceBundleBuilder = serviceBundleBuilder();
    serviceBundleBuilder.getRequestQueueBuilder().setBatchSize(1);
    final ServiceBundle serviceBundle = serviceBundleBuilder.build();

    /** Create implementation. */
    final TodoManagerImpl todoManagerImpl = new TodoManagerImpl(Reactor.reactor(), new StatsCollector() {
    });

    /** Add implementation to service bundle. */
    serviceBundle.addServiceObject("todo", todoManagerImpl);
    final TodoManager todoManager = serviceBundle.createLocalProxy(TodoManager.class, "todo");
    serviceBundle.start();

    /** Add a Todo. */
    final Promise<Boolean> addPromise = blockingPromise();
    todoManager.add(new Todo("Buy Tesla", "Buy new Tesla", System.currentTimeMillis()))
            .catchError(Throwable::printStackTrace).invokeWithPromise(addPromise);
    assertTrue(addPromise.get());

    /** Call list to get a list of Todos. */
    final Promise<List<Todo>> listPromise = blockingPromise();
    todoManager.list().invokeWithPromise(listPromise);
    final List<Todo> todos = listPromise.get();
    assertEquals(1, todos.size());
    assertEquals("Buy Tesla", todos.get(0).getName());

    /** Get the id of the Todo to remove it. */
    final String id = todos.get(0).getId();

    /** Remove the todo with the todo id.  */
    final Promise<Boolean> removePromise = blockingPromise();
    todoManager.remove(id).invokeWithPromise(removePromise);
    assertTrue(removePromise.get());

    /** See if the todo was removed.  */
    final Promise<List<Todo>> listPromise2 = blockingPromise();
    todoManager.list().invokeWithPromise(listPromise2);
    final List<Todo> todos2 = listPromise2.get();
    assertEquals(0, todos2.size());

}
 
開發者ID:MammatusTech,項目名稱:qbit-microservices-examples,代碼行數:46,代碼來源:TodoManagerTest.java

示例5: noOverloadingBundle

import io.advantageous.qbit.service.ServiceBundleBuilder; //導入依賴的package包/類
@Test //(expected = IllegalStateException.class)
public void noOverloadingBundle() {

    ServiceBundleBuilder.serviceBundleBuilder().build().addService(new MyService()).start();
}
 
開發者ID:advantageous,項目名稱:qbit,代碼行數:6,代碼來源:Bug384.java

示例6: setup

import io.advantageous.qbit.service.ServiceBundleBuilder; //導入依賴的package包/類
@Before
public void setup() {
    systemManager = new QBitSystemManager();
    myServiceList = new ArrayList<>(numServices);

    for (int index = 0; index < numServices; index++) {
        myServiceList.add(new MyService());
    }

    final AtomicInteger serviceCount = new AtomicInteger();

    serviceBundleBuilder = ServiceBundleBuilder.serviceBundleBuilder().setSystemManager(systemManager);
    serviceBundle = serviceBundleBuilder.build();


    serviceBundle.addRoundRobinService("/myService", numServices, () -> myServiceList.get(serviceCount.getAndIncrement()));
    serviceBundle.start();

    myService = serviceBundle.createLocalProxy(IMyService.class, "/myService");

}
 
開發者ID:advantageous,項目名稱:qbit,代碼行數:22,代碼來源:ServiceWorkersTest.java

示例7: testServer

import io.advantageous.qbit.service.ServiceBundleBuilder; //導入依賴的package包/類
@Test
public void testServer() {

    super.setupLatch();

    ProtocolEncoder encoder = QBit.factory().createEncoder();

    ProtocolParser parser = QBit.factory().createProtocolParser();
    MockHttpServer httpServer = new MockHttpServer();
    final ServiceBundle serviceBundle = new ServiceBundleBuilder().setAddress("/services").build();

    JsonMapper mapper = new BoonJsonMapper();

    ServiceEndpointServerImpl server = new ServiceEndpointServerImpl(httpServer, encoder,
            parser, serviceBundle, mapper, 30, 100, 30, 10, null, null, null, null, null, "localhost", 8080, 0, null, null, 50, 2, 2);

    server.initServices(Sets.set(new TodoService()));

    final AtomicBoolean resultsWorked = new AtomicBoolean();

    server.start();

    httpServer.postRequestObject("/services/todo-manager/todo", new Todo("Call Dad", "Call Dad", new Date()), (code, mimeType, body) -> {

        puts("CALL CALLED", body, "\n\n");
        if (body != null && code == 202 && body.equals("\"success\"")) {
            resultsWorked.set(true);
        }
    });

    waitForTrigger(20, o -> resultsWorked.get());

    if (!resultsWorked.get()) {
        die("Add operation did not work");
    }

    resultsWorked.set(false);

    httpServer.sendHttpGet("/services/todo-manager/todo/list/", null, (code, mimeType, body) -> {

        puts("ADD CALL RESPONSE code ", code, " mimeType ", mimeType, " body ", body);

        List<Todo> todos = fromJsonArray(body, Todo.class);
        if (todos.size() > 0) {
            Todo todo = todos.get(0);
            if (todo.getDescription().equals("Call Dad")) {
                resultsWorked.set(true);
            }
        }
    });

    server.serviceBundle().flushSends();
    Sys.sleep(100);
    server.flush();
    Sys.sleep(100);

    waitForTrigger(20, o -> resultsWorked.get());

    if (!resultsWorked.get()) {
        die("List operation did not work");
    }

}
 
開發者ID:advantageous,項目名稱:qbit,代碼行數:64,代碼來源:ServerTest.java

示例8: testServerTimeout

import io.advantageous.qbit.service.ServiceBundleBuilder; //導入依賴的package包/類
@Test
public void testServerTimeout() {

    ProtocolEncoder encoder = QBit.factory().createEncoder();
    MockHttpServer httpServer = new MockHttpServer();

    final ServiceBundle serviceBundle = new ServiceBundleBuilder().setAddress("/services").build();
    JsonMapper mapper = new BoonJsonMapper();

    ServiceEndpointServerImpl server = new ServiceEndpointServerImpl(httpServer, encoder,
            QBit.factory().createProtocolParser(), serviceBundle, mapper, 1, 100, 30,
            10, null,
            null, null, null, null, "localhost", 8080, 0, null, null, 50, 2, 2);

    server.initServices(Sets.set(new TodoService()));

    server.start();

    final AtomicBoolean resultsWorked = new AtomicBoolean();

    for (int index = 0; index < 100; index++) {

        httpServer.sendHttpGet("/services/todo-manager/timeout", null, (code, mimeType, body) -> {

            if (code == 408 && body != null && body.equals("\"timed out\"")) {
                resultsWorked.set(true);
            }
        });
    }

    server.serviceBundle().flushSends();
    Sys.sleep(100);
    Sys.sleep(100);
    server.flush();
    Sys.sleep(100);

    waitForTrigger(8, o -> resultsWorked.get());

    if (!resultsWorked.get()) {
        die(" we did not get timeout");
    }

    resultsWorked.set(false);

}
 
開發者ID:advantageous,項目名稱:qbit,代碼行數:46,代碼來源:ServerTest.java

示例9: setup

import io.advantageous.qbit.service.ServiceBundleBuilder; //導入依賴的package包/類
@Before
public void setup() {


    /* Create the serviceBundleBuilder. */
    final ServiceBundleBuilder serviceBundleBuilder = serviceBundleBuilder();

    /* Create the service bundle. */
    serviceBundle = serviceBundleBuilder.build();

    /* Add the AuditorImpl instance to the serviceBundle. */
    serviceBundle.addServiceObject(auditorAddress, new AuditorImpl());

    /* Create a service client proxy for the auditor. */
    auditor = serviceBundle.createLocalProxy(Auditor.class, auditorAddress);

    /* Create a todo manager and pass the client proxy of the auditor to it. */
    final TodoManagerImpl todoManager = new TodoManagerImpl(auditor);

    // Add the todoManager to the serviceBundle.
    serviceBundle
            .addServiceObject(todoAddress, todoManager);

    //Create a client proxy to communicate with the service actor.
    client = serviceBundle.createLocalProxy(TodoManagerClient.class, todoAddress);

    // Start the service bundle.
    serviceBundle.start();


}
 
開發者ID:MammatusTech,項目名稱:qbit-microservices-examples,代碼行數:32,代碼來源:TodoManagerImplTest.java

示例10: setup

import io.advantageous.qbit.service.ServiceBundleBuilder; //導入依賴的package包/類
@Before
public void setup() {
    systemManager = new QBitSystemManager();

    eventManager = EventManagerBuilder
            .eventManagerBuilder().setName("Event Bus")
            .build();


    serviceBundleBuilder = ServiceBundleBuilder.serviceBundleBuilder()
            .setEventManager(eventManager)
            .setSystemManager(systemManager);

    final ServiceBundle serviceBundle = serviceBundleBuilder.buildAndStart();

    serviceBundle.addServiceObject("eventManager", eventManager);


    serviceB = new ServiceB();

    serviceBundle.addServiceObject("serviceB", serviceB);


    ServiceA serviceA = new ServiceA(serviceBundle.createLocalProxy(EventManager.class, "eventManager"));


    serviceBundle.addServiceObject("serviceA", serviceA);


    serviceAQueueProxy = serviceBundle.createLocalProxy(ServiceAInterface.class, "serviceA");

    serviceBundle.startReturnHandlerProcessor();

}
 
開發者ID:advantageous,項目名稱:qbit,代碼行數:35,代碼來源:SendingEventsUsingLooselyTypeChannelAndServiceBundleTest.java

示例11: callingServicesThatThrowExceptions

import io.advantageous.qbit.service.ServiceBundleBuilder; //導入依賴的package包/類
public void callingServicesThatThrowExceptions() {


        @RequestMapping("myService")
        class MyServiceClass {


            public String methodThrowsExceptionIf5(String hi, int amount) {

                if (amount == 5) {
                    return die(String.class, "Hi " + hi + " " + amount);
                } else {
                    return "Hi " + hi + " " + amount;
                }
            }
        }


        MyServiceClass myService = new MyServiceClass();

        final ServiceBundle serviceBundle = new ServiceBundleBuilder().setAddress("/root").buildAndStart();


        serviceBundle.addService(myService);
        serviceBundle.startReturnHandlerProcessor();


        final ClientInterfaceThrowsException myServiceProxy = serviceBundle.createLocalProxy(
                ClientInterfaceThrowsException.class,
                "myService");

        ok = false;

        AtomicBoolean wasError = new AtomicBoolean();
        final Callback<String> handler = new Callback<String>() {

            @Override
            public void accept(String s) {

                ok = true;
            }

            @Override
            public void onError(Throwable error) {

                puts("We got", error.getMessage());

                ok = "Hi hi 5".equals(error.getMessage());
                wasError.set(true);
            }
        };

        myServiceProxy.methodThrowsExceptionIf5(handler, "hi", 6);
        serviceBundle.flush();
        Sys.sleep(5000);

        ok = ok || die();

        ok = !wasError.get() || die();

        ok = false;
        wasError.set(false);

        Sys.sleep(100);


        myServiceProxy.methodThrowsExceptionIf5(handler, "hi", 5);
        serviceBundle.flush();
        Sys.sleep(2000);


        ok = wasError.get() || die();


    }
 
開發者ID:advantageous,項目名稱:qbit,代碼行數:76,代碼來源:ServiceProxyFactoryTest.java

示例12: testWithBundleUsingAddress

import io.advantageous.qbit.service.ServiceBundleBuilder; //導入依賴的package包/類
@Test
public void testWithBundleUsingAddress() {

    final ServiceBundle serviceBundle = new ServiceBundleBuilder().setAddress("/services").buildAndStart();

    serviceBundle.addService(new TodoService());


    Todo todoItem = new Todo("call mom", "give mom a call", new Date());

    MethodCall<Object> addMethod =
            MethodCallBuilder.methodCallBuilder().setAddress("/services/todo-manager").setName("add").setReturnAddress("client1").setBody(todoItem).build();


    serviceBundle.call(addMethod);


    MethodCall<Object> listMethod =
            MethodCallBuilder.methodCallBuilder().setAddress("/services/todo-manager").setName("list").setReturnAddress("client1").setBody(todoItem).build();


    serviceBundle.call(listMethod);

    serviceBundle.flush();

    Sys.sleep(100);

    ReceiveQueue<Response<Object>> responses = serviceBundle.responses().receiveQueue();

    Response<Object> response = responses.take();

    Object body = response.body();

    if (body instanceof List) {
        @SuppressWarnings("unchecked") List<Todo> items = (List) body;

        ok = items.size() > 0 || die("items should have one todo in it");

        Todo todoItem1 = items.get(0);

        ok = todoItem.equals(todoItem1) || die("TodoItem ", todoItem, todoItem1);


    } else {
        die("Response was not a list", body);
    }


}
 
開發者ID:advantageous,項目名稱:qbit,代碼行數:50,代碼來源:TodoServiceWithServiceBundleTest.java

示例13: testWithBundleUsingObjectName

import io.advantageous.qbit.service.ServiceBundleBuilder; //導入依賴的package包/類
@Test
public void testWithBundleUsingObjectName() {
    final ServiceBundle serviceBundle = new ServiceBundleBuilder().setAddress("/services").buildAndStart();

    serviceBundle.addService(new TodoService());


    Todo todoItem = new Todo("call mom", "give mom a call", new Date());
    MethodCall<Object> addMethodCall = QBit.factory().createMethodCallByNames("add", "/services/todo-manager", "call1:localhost", todoItem, null);

    serviceBundle.call(addMethodCall);


    MethodCall<Object> listMethodCall = QBit.factory().createMethodCallByNames("list", "/services/todo-manager", "call2:localhost", todoItem, null);

    serviceBundle.call(listMethodCall);

    serviceBundle.flush();


    Sys.sleep(100);

    ReceiveQueue<Response<Object>> responses = serviceBundle.responses().receiveQueue();

    Response<Object> response = responses.take();

    Object body = response.body();

    if (body instanceof List) {
        @SuppressWarnings("unchecked") List<Todo> items = (List) body;

        ok = items.size() > 0 || die("items should have one todo in it");

        Todo todoItem1 = items.get(0);

        ok = todoItem.equals(todoItem1) || die("TodoItem ", todoItem, todoItem1);


    } else {
        die("Response was not a list", body);
    }


}
 
開發者ID:advantageous,項目名稱:qbit,代碼行數:45,代碼來源:TodoServiceWithServiceBundleTest.java

示例14: testNoMethodCallFound

import io.advantageous.qbit.service.ServiceBundleBuilder; //導入依賴的package包/類
@Test
public void testNoMethodCallFound() {

    ProtocolEncoder encoder = QBit.factory().createEncoder();
    MockHttpServer httpServer = new MockHttpServer();

    final ServiceBundle serviceBundle = new ServiceBundleBuilder().setAddress("/root").build();

    JsonMapper mapper = new BoonJsonMapper();

    ServiceEndpointServerImpl server = new ServiceEndpointServerImpl(
            httpServer, encoder, QBit.factory().createProtocolParser(), serviceBundle, mapper, 1, 100, 30, 10,
            null, null, null, null, null, "localhost", 8080, 0, null, null, 50, 2, 2);

    server.initServices(new TodoService());

    server.start();

    final AtomicBoolean resultsWorked = new AtomicBoolean();

    resultsWorked.set(false);

    httpServer.sendHttpGet("/services/todo-manager/testNoMethodCallFound", null, (code, mimeType, body) -> {

        if (code == 404) {
            resultsWorked.set(true);
        }
    });

    server.serviceBundle().flushSends();
    Sys.sleep(100);
    Sys.sleep(100);
    server.flush();
    Sys.sleep(100);

    waitForTrigger(20, o -> resultsWorked.get());

    if (!resultsWorked.get()) {
        die(" we did not get timeout");
    }

    resultsWorked.set(false);

}
 
開發者ID:advantageous,項目名稱:qbit,代碼行數:45,代碼來源:ServerTest.java

示例15: testWithServiceQueue

import io.advantageous.qbit.service.ServiceBundleBuilder; //導入依賴的package包/類
@Test
public void testWithServiceQueue() {

    final Factory factory = QBit.factory();
    final ProtocolParser protocolParser = factory.createProtocolParser();
    final ProtocolEncoder encoder = factory.createEncoder();

    final Queue<Response<Object>> responseQueue = QueueBuilder.queueBuilder().setName("RESPONSE QUEUE TEST").build();

    final ServiceBundle serviceBundle = new ServiceBundleBuilder()
            .setResponseQueue(responseQueue).setAddress("/services").build();
    final JsonMapper mapper = factory.createJsonMapper();

    httpServer = new HttpServerMock();
    serviceServerImpl = new ServiceEndpointServerImpl(httpServer, encoder, protocolParser, serviceBundle,
            mapper, 1, 100, 30, 10, null, null, null, null, null, "localhost", 8080, 0, null, null, 50, 2, 2);

    callMeCounter = 0;
    responseCounter = 0;

    ServiceQueue serviceQueue = serviceBuilder()
            .setResponseQueue(responseQueue)
            .setServiceObject(new MyOtherService()).buildAndStart();

    serviceServerImpl.addServiceQueue("/services/other/serviceCall", serviceQueue);

    serviceServerImpl.start();

    final HttpRequest request = new HttpRequestBuilder().setUri("/services/other/servicecall")
            .setTextReceiver(new MockReceiver()).setBody("\"call\"").build();

    httpServer.sendRequest(request);

    Sys.sleep(100);

    waitForTrigger(20, o -> responseCounter == 1 && callMeCounter == 1);

    ok |= responseCounter == 1 || die();
    ok |= callMeCounter == 1 || die();

}
 
開發者ID:advantageous,項目名稱:qbit,代碼行數:42,代碼來源:ServiceEndpointServerImplTest.java


注:本文中的io.advantageous.qbit.service.ServiceBundleBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。