Search in sources :

Example 1 with ClientLifeCycleListener

use of org.apache.cxf.endpoint.ClientLifeCycleListener in project cxf by apache.

the class OSGiBusListenerTest method setUpClientLifeCycleListeners.

private void setUpClientLifeCycleListeners(String[] names, String[] restricted, String excludes) throws Exception {
    ServiceReference<Object>[] svcrefs = createTestServiceReferences(names, restricted);
    EasyMock.expect(bundleContext.getServiceReferences(ClientLifeCycleListener.class.getName(), null)).andReturn(svcrefs);
    ClientLifeCycleManager lcmanager = control.createMock(ClientLifeCycleManager.class);
    EasyMock.expect(bus.getExtension(ClientLifeCycleManager.class)).andReturn(lcmanager).anyTimes();
    for (int i = 0; i < names.length; i++) {
        ClientLifeCycleListener cl = control.createMock(ClientLifeCycleListener.class);
        EasyMock.expect(bundleContext.getService(svcrefs[i])).andReturn(cl).anyTimes();
        if (!isExcluded(BUNDLE_NAME, names[i], restricted[i], excludes)) {
            lcmanager.registerListener(cl);
            EasyMock.expectLastCall();
        }
    }
}
Also used : ClientLifeCycleListener(org.apache.cxf.endpoint.ClientLifeCycleListener) ClientLifeCycleManager(org.apache.cxf.endpoint.ClientLifeCycleManager) ServiceReference(org.osgi.framework.ServiceReference)

Example 2 with ClientLifeCycleListener

use of org.apache.cxf.endpoint.ClientLifeCycleListener in project cxf by apache.

the class RMManager method registerListeners.

@PostConstruct
void registerListeners() {
    if (null == bus) {
        return;
    }
    ServerLifeCycleManager slm = bus.getExtension(ServerLifeCycleManager.class);
    if (null != slm) {
        slm.registerListener(new ServerLifeCycleListener() {

            public void startServer(Server server) {
                RMManager.this.startServer(server);
            }

            public void stopServer(Server server) {
                RMManager.this.stopServer(server);
            }
        });
    }
    ClientLifeCycleManager clm = bus.getExtension(ClientLifeCycleManager.class);
    if (null != clm) {
        clm.registerListener(new ClientLifeCycleListener() {

            public void clientCreated(Client client) {
                RMManager.this.clientCreated(client);
            }

            public void clientDestroyed(Client client) {
                RMManager.this.clientDestroyed(client);
            }
        });
    }
}
Also used : ClientLifeCycleListener(org.apache.cxf.endpoint.ClientLifeCycleListener) Server(org.apache.cxf.endpoint.Server) ServerLifeCycleManager(org.apache.cxf.endpoint.ServerLifeCycleManager) ClientLifeCycleManager(org.apache.cxf.endpoint.ClientLifeCycleManager) ServerLifeCycleListener(org.apache.cxf.endpoint.ServerLifeCycleListener) Client(org.apache.cxf.endpoint.Client) PostConstruct(javax.annotation.PostConstruct)

Example 3 with ClientLifeCycleListener

use of org.apache.cxf.endpoint.ClientLifeCycleListener in project cxf by apache.

the class LifeCycleTest method testClientLifecycle.

@Test
public void testClientLifecycle() throws Exception {
    final AtomicBoolean created = new AtomicBoolean();
    final AtomicBoolean destroyed = new AtomicBoolean();
    bus.getExtension(ClientLifeCycleManager.class).registerListener(new ClientLifeCycleListener() {

        public void clientCreated(Client client) {
            created.set(true);
        }

        public void clientDestroyed(Client client) {
            destroyed.set(true);
        }
    });
    org.apache.hello_world_soap_http.SOAPService service = new org.apache.hello_world_soap_http.SOAPService();
    Greeter client = service.getSoapPort();
    ((BindingProvider) client).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ADDRESSES[0]);
    assertTrue("clientCreated not called", created.get());
    client = null;
    int count = 0;
    while (count < 10 && !destroyed.get()) {
        System.gc();
        System.runFinalization();
        count++;
        if (count > 5) {
            Thread.sleep(100);
        }
    }
    assertTrue("clientDestroyed not called", destroyed.get());
    created.set(false);
    destroyed.set(false);
    client = service.getSoapPort();
    ((BindingProvider) client).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ADDRESSES[0]);
    assertTrue("clientCreated not called", created.get());
    ((java.io.Closeable) client).close();
    assertTrue("clientDestroyed not called", destroyed.get());
}
Also used : Endpoint(javax.xml.ws.Endpoint) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientLifeCycleListener(org.apache.cxf.endpoint.ClientLifeCycleListener) ClientLifeCycleManager(org.apache.cxf.endpoint.ClientLifeCycleManager) Greeter(org.apache.hello_world_soap_http.Greeter) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Example 4 with ClientLifeCycleListener

use of org.apache.cxf.endpoint.ClientLifeCycleListener in project cxf by apache.

the class OSGIBusListener method registerClientLifeCycleListeners.

private void registerClientLifeCycleListeners() {
    ServiceReference<?>[] refs = getServiceReferences(defaultContext, ClientLifeCycleListener.class);
    ClientLifeCycleManager clcm = bus.getExtension(ClientLifeCycleManager.class);
    for (ServiceReference<?> ref : refs) {
        if (!isPrivate(ref) && !isExcluded(ref)) {
            ClientLifeCycleListener listener = (ClientLifeCycleListener) defaultContext.getService(ref);
            clcm.registerListener(listener);
        }
    }
}
Also used : ClientLifeCycleListener(org.apache.cxf.endpoint.ClientLifeCycleListener) ClientLifeCycleManager(org.apache.cxf.endpoint.ClientLifeCycleManager) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

ClientLifeCycleListener (org.apache.cxf.endpoint.ClientLifeCycleListener)4 ClientLifeCycleManager (org.apache.cxf.endpoint.ClientLifeCycleManager)4 Client (org.apache.cxf.endpoint.Client)2 ServiceReference (org.osgi.framework.ServiceReference)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 PostConstruct (javax.annotation.PostConstruct)1 Endpoint (javax.xml.ws.Endpoint)1 Server (org.apache.cxf.endpoint.Server)1 ServerLifeCycleListener (org.apache.cxf.endpoint.ServerLifeCycleListener)1 ServerLifeCycleManager (org.apache.cxf.endpoint.ServerLifeCycleManager)1 Greeter (org.apache.hello_world_soap_http.Greeter)1 Test (org.junit.Test)1