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