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();
}
}
}
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);
}
});
}
}
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());
}
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);
}
}
}
Aggregations