/** * creates a new container instance. * * @param description the container type description. * @param parameters the parameter passed to the container constructor. * @return the factored container instance. * @see * org.eclipse.ecf.core.provider.IContainerInstantiator#createInstance(org.eclipse.ecf.core.ContainerTypeDescription, * java.lang.Object[]) */ public IContainer createInstance( final ContainerTypeDescription description, final Object[] parameters) throws ContainerCreateException { try { final RemoteOSGiService remoteOSGiService = Activator.getDefault().getRemoteOSGiService(); String descriptionName = description.getName(); boolean wss = descriptionName.equals(ROSGI_WEBSOCKETSS_CONFIG); boolean ws = (descriptionName.equals(ROSGI_WEBSOCKETS_CONFIG) || wss); Namespace ns = (wss ? R_OSGiWSSNamespace.getDefault() : ((ws) ? R_OSGiWSNamespace.getDefault() : R_OSGiNamespace.getDefault())); ID containerID = null; if (parameters == null) { String localHost = "localhost"; // $NON-NLS-1$ if (useHostname) { try { localHost = InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { // Ignore } } final String nsScheme = ns.getScheme(); final String wsProtocol = (wss ? WSS_PROTOCOL : (ws ? WS_PROTOCOL : null)); int listeningPort = remoteOSGiService.getListeningPort((wsProtocol != null) ? wsProtocol : nsScheme); int idPort = -1; if (WSS_PROTOCOL.equals(wsProtocol) && listeningPort != WSS_DEFAULT_PORT) idPort = listeningPort; else if (WS_PROTOCOL.equals(wsProtocol) && listeningPort != WS_DEFAULT_PORT) idPort = listeningPort; String portStr = (idPort > 0 ? (":" + idPort) : ""); // $NON-NLS-1$ //$NON-NLS-2$ containerID = createR_OSGiID(ns, new String(nsScheme + "://" + localHost + portStr)); // $NON-NLS-1$ } else if (parameters.length > 0) { if (parameters[0] instanceof ID) containerID = (ID) parameters[0]; else if (parameters[0] instanceof String) containerID = createR_OSGiID(ns, (String) parameters[0]); else if (parameters[0] instanceof Map) { Map params = (Map) parameters[0]; String idStr = (String) params.get(ID_PROP); if (idStr == null) throw new NullPointerException("No ID prop found in parameters map"); // $NON-NLS-1$ containerID = createR_OSGiID(ns, idStr); } } if (containerID == null) throw new ContainerCreateException( "Unsupported arguments " //$NON-NLS-1$ + Arrays.asList(parameters)); if (wss) return new R_OSGiWSSRemoteServiceContainer(remoteOSGiService, containerID); else if (ws) return new R_OSGiWSRemoteServiceContainer(remoteOSGiService, containerID); else return new R_OSGiRemoteServiceContainer(remoteOSGiService, containerID); } catch (Exception e) { throw new ContainerCreateException("Could not create R_OSGI ID", e); // $NON-NLS-1$ } }
/** * @param hostname * @param port * @param name * @param keepAlive */ protected void setupServerFromParameters(String hostname, int port, String name, int keepAlive) throws IOException, IDCreateException { final String hostnamePort = hostname + ":" + port; // $NON-NLS-1$ synchronized (serverGroups) { SSLServerSOContainerGroup serverGroup = (SSLServerSOContainerGroup) serverGroups.get(hostnamePort); if (serverGroup == null) { System.out.println( "Putting server " + hostnamePort + " on the air..."); // $NON-NLS-1$ //$NON-NLS-2$ try { serverGroup = new SSLServerSOContainerGroup(hostname, port); final String url = SSLServerSOContainer.DEFAULT_PROTOCOL + "://" //$NON-NLS-1$ + hostnamePort + name; // Create final SSLServerSOContainer container = createServerContainer(url, serverGroup, name, keepAlive); // Configure configureServerContainer(container); // Put on the air serverGroup.putOnTheAir(); } catch (final IOException e) { e.printStackTrace(System.err); throw e; } catch (IDCreateException e) { e.printStackTrace(System.err); throw e; } serverGroups.put(hostnamePort, serverGroup); System.out.println( "SSLGenericServerContainer " + hostnamePort + " on the air."); //$NON-NLS-1$ //$NON-NLS-2$ } else { System.out.println( "SSLGenericServerContainer " + hostnamePort //$NON-NLS-1$ + " already on the air. No changes made."); //$NON-NLS-1$ } } }
protected void setupServerFromConfig(List connectors) throws IOException, IDCreateException { for (final Iterator i = connectors.iterator(); i.hasNext(); ) { final Connector connector = (Connector) i.next(); final String hostname = connector.getHostname(); final int port = connector.getPort(); final String hostnamePort = hostname + ":" + port; // $NON-NLS-1$ SSLServerSOContainerGroup serverGroup = null; synchronized (serverGroups) { serverGroup = (SSLServerSOContainerGroup) serverGroups.get(hostnamePort); if (serverGroup == null) { System.out.println( "Putting server " + hostnamePort + " on the air..."); // $NON-NLS-1$ //$NON-NLS-2$ serverGroup = new SSLServerSOContainerGroup(hostname, port); final List groups = connector.getGroups(); for (final Iterator g = groups.iterator(); g.hasNext(); ) { final NamedGroup group = (NamedGroup) g.next(); // Create final SSLServerSOContainer container = createServerContainer( group.getIDForGroup(), serverGroup, group.getName(), connector.getTimeout()); // Configure configureServerContainer(container); } serverGroup.putOnTheAir(); serverGroups.put(hostnamePort, serverGroup); System.out.println( "GenericServerContainer " + hostnamePort //$NON-NLS-1$ + " on the air."); //$NON-NLS-1$ } else { System.out.println( "GenericServerContainer " + hostnamePort //$NON-NLS-1$ + " already on the air. No changes made."); //$NON-NLS-1$ } } } }
/* * (non-Javadoc) * * @see org.eclipse.equinox.app.IApplication#stop() */ public void stop() { synchronized (serverGroups) { for (final Iterator i = serverGroups.keySet().iterator(); i.hasNext(); ) { final SSLServerSOContainerGroup serverGroup = (SSLServerSOContainerGroup) serverGroups.get(i.next()); serverGroup.takeOffTheAir(); System.out.println( "Taking " + serverGroup.getName() + ":" + serverGroup.getPort() + " off the air"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ final Iterator iter = serverGroup.elements(); for (; iter.hasNext(); ) { final SSLServerSOContainer container = (SSLServerSOContainer) iter.next(); container.dispose(); } } } serverGroups.clear(); synchronized (this) { this.notify(); } }