Search in sources :

Example 41 with ServiceInfo

use of javax.jmdns.ServiceInfo in project ecf by eclipse.

the class JMDNSDiscoveryContainer method createIServiceInfoFromServiceInfo.

IServiceInfo createIServiceInfoFromServiceInfo(final ServiceInfo serviceInfo) throws Exception {
    Assert.isNotNull(serviceInfo);
    final int priority = serviceInfo.getPriority();
    final int weight = serviceInfo.getWeight();
    final Properties props = new Properties();
    String uriProtocol = null;
    String uriPath = null;
    String namingAuthority = IServiceTypeID.DEFAULT_NA;
    for (final Enumeration e = serviceInfo.getPropertyNames(); e.hasMoreElements(); ) {
        final String key = (String) e.nextElement();
        if (SCHEME_PROPERTY.equals(key)) {
            uriProtocol = serviceInfo.getPropertyString(key);
        } else if (NAMING_AUTHORITY_PROPERTY.equals(key)) {
            namingAuthority = serviceInfo.getPropertyString(key);
        } else if (URI_PATH_PROPERTY.equals(key)) {
            uriPath = serviceInfo.getPropertyString(key);
        } else {
            final byte[] bytes = serviceInfo.getPropertyBytes(key);
            try {
                final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
                final Object object = in.readObject();
                in.close();
                props.put(key, object);
            } catch (final StreamCorruptedException ioe) {
                props.put(key, serviceInfo.getPropertyString(key));
            } catch (final EOFException eofe) {
                // not all byte[] are serialized objs (e.g. a native service)
                props.put(key, serviceInfo.getPropertyString(key));
            }
        }
    }
    // proto
    final String proto = serviceInfo.getProtocol();
    // scopes
    final String domain = serviceInfo.getDomain();
    final String[] scopes = new String[] { domain };
    // uri
    String authority = serviceInfo.getHostAddress() + ":" + serviceInfo.getPort();
    final URI uri = new URI(uriProtocol == null ? proto : uriProtocol, authority, uriPath, null, null);
    // service type
    String st = serviceInfo.getType();
    final int end = st.indexOf(proto);
    String[] types = StringUtils.split(st.substring(1, end), "._");
    final IServiceTypeID sID = ServiceIDFactory.getDefault().createServiceTypeID(getServicesNamespace(), types, scopes, new String[] { proto }, namingAuthority);
    // service name
    final String name = serviceInfo.getName();
    return new org.eclipse.ecf.discovery.ServiceInfo(uri, name, sID, priority, weight, new ServiceProperties(props));
}
Also used : URI(java.net.URI) ServiceInfo(javax.jmdns.ServiceInfo)

Example 42 with ServiceInfo

use of javax.jmdns.ServiceInfo in project ecf by eclipse.

the class JMDNSDiscoveryContainer method unregisterService.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#unregisterService(org.eclipse.ecf.discovery.IServiceInfo)
	 */
public void unregisterService(final IServiceInfo serviceInfo) {
    Assert.isNotNull(serviceInfo);
    final ServiceInfo si = createServiceInfoFromIServiceInfo(serviceInfo);
    jmdns.unregisterService(si);
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo)

Example 43 with ServiceInfo

use of javax.jmdns.ServiceInfo in project Openfire by igniterealtime.

the class MulticastDNSService method start.

@Override
public void start() throws IllegalStateException {
    // If the service isn't enabled, return.
    if (!JiveGlobals.getBooleanProperty("multicastDNS.enabled", false)) {
        return;
    }
    TimerTask startService = new TimerTask() {

        @Override
        public void run() {
            int clientPortNum = -1;
            int componentPortNum = -1;
            final ConnectionManager connectionManager = XMPPServer.getInstance().getConnectionManager();
            if (connectionManager != null) {
                clientPortNum = connectionManager.getClientListenerPort();
                componentPortNum = connectionManager.getComponentListenerPort();
            }
            try {
                if (jmdns == null) {
                    jmdns = new JmDNS();
                }
                String serverName = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
                if (clientPortNum != -1) {
                    ServiceInfo clientService = new ServiceInfo("_xmpp-client._tcp.local.", serverName + "._xmpp-client._tcp.local.", clientPortNum, "XMPP Server");
                    jmdns.registerService(clientService);
                }
                if (componentPortNum != -1) {
                    ServiceInfo componentService = new ServiceInfo("_xmpp-component._tcp.local.", serverName + "._xmpp-component._tcp.local.", componentPortNum, "XMPP Component Server");
                    jmdns.registerService(componentService);
                }
            } catch (IOException ioe) {
                Log.error(ioe.getMessage(), ioe);
            }
        }
    };
    // Schedule the task to run in 5 seconds, to give Wildire time to start the ports.
    TaskEngine.getInstance().schedule(startService, 5000);
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) ConnectionManager(org.jivesoftware.openfire.ConnectionManager) JmDNS(javax.jmdns.JmDNS) TimerTask(java.util.TimerTask) IOException(java.io.IOException)

Aggregations

ServiceInfo (javax.jmdns.ServiceInfo)43 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)14 JmDNS (javax.jmdns.JmDNS)11 List (java.util.List)10 LinkedList (java.util.LinkedList)7 HashMap (java.util.HashMap)6 ExecutorService (java.util.concurrent.ExecutorService)6 SocketException (java.net.SocketException)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 DNSOutgoing (javax.jmdns.impl.DNSOutgoing)4 Inet4Address (java.net.Inet4Address)3 Inet6Address (java.net.Inet6Address)3 InetAddress (java.net.InetAddress)3 URI (java.net.URI)3 ExecutionException (java.util.concurrent.ExecutionException)3 HashSet (java.util.HashSet)2 Callable (java.util.concurrent.Callable)2 Future (java.util.concurrent.Future)2 ServiceEvent (javax.jmdns.ServiceEvent)2