|
||||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
The Web Container registers an object implementing this service with the framework, under the name of this interface. Bundles can use this service to dynamically configure the Web Container transports (i.e ports) at runtime. A Web Container transport is a thread listening on a specified port.
Bundles should use a ServiceTracker to track the SocketConfigService object.
The following example shows how to :
public class MyActivator implements BundleActivator { private ServiceTracker myServiceTracker; private BundleContext context; public void start(BundleContext bc) throws Exception { context = bc; myServiceTracker = new ServiceTracker(bc, SocketConfigService.class.getName(), new MyServiceTracker(context)); myServiceTracker.open(); } public void stop(BundleContext bc) throws Exception { myServiceTracker.close(); } } public class MyServiceTracker implements ServiceTrackerCustomizer { private BundleContext context = null; private ServerSocket socket = null; private SocketConfigService service = null; public MyServiceTracker(BundleContext bc) { context = bc; } public Object addingService(ServiceReference reference) { service = (SocketConfigService) context.getService(reference); if(service != null) { try { // create a ServerSocket socket = new ServerSocket(9999); // configure Web Container to listen on port 9999 service.startTransport(socket); } catch (SocketConfigException sce) { // handle exception } catch (IOException ioe) { // handle exception } catch (SecurityException se) { // handle exception } } } public void removedService(ServiceReference reference, Object service) { if(service != null) { // shutdown transport service.stopTransport(socket); } } }
Method Summary | |
---|---|
void |
startTransport(java.net.ServerSocket socket)
Start a Web Container transport with the specified server socket |
void |
stopTransport(java.net.ServerSocket socket)
Stop the Web Container transport that was started using startTransport |
Method Detail |
public void startTransport(java.net.ServerSocket socket) throws SocketConfigException
socket
- a ServerSocket (NOTE: use a SSLServerSocket for secure communication)
SocketConfigException
- - if problem occurs during configurationpublic void stopTransport(java.net.ServerSocket socket)
socket
- a ServerSocket (NOTE: use the same socket used for startTransport)
|
||||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |