本文整理汇总了Java中javax.jmdns.ServiceInfo类的典型用法代码示例。如果您正苦于以下问题:Java ServiceInfo类的具体用法?Java ServiceInfo怎么用?Java ServiceInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServiceInfo类属于javax.jmdns包,在下文中一共展示了ServiceInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addService
import javax.jmdns.ServiceInfo; //导入依赖的package包/类
/**
* Publish a zeroconf service.
*
* Should actually provide a return value here, so the user can see the
* actually published name.
*
* @param name : english readable name for the service
* @param type : zeroconf service type, e.g. _ros-master._tcp
* @param domain : domain to advertise on (usually 'local')
* @param port : port number
* @param description :
*/
public void addService(String name, String type, String domain, int port, String description) {
String full_service_type = type + "." + domain + ".";
logger.println("Registering service: " + full_service_type);
String service_key = "description"; // Max 9 chars
HashMap<String, byte[]> properties = new HashMap<String, byte[]>();
properties.put(service_key,description.getBytes());
ServiceInfo service_info = ServiceInfo.create(full_service_type, name, port, 0, 0, true, properties);
// we need much better logic here to handle duplications.
if ( services.add(service_info) ) {
try {
jmmdns.registerService(service_info);
} catch (IOException e) {
e.printStackTrace();
}
}
// this is broken - it adds it, but fails to resolve it on other systems
// https://sourceforge.net/tracker/?func=detail&aid=3435220&group_id=93852&atid=605791
// services.add(ServiceInfo.create(service_type, service_name, service_port, 0, 0, true, text));
}
示例2: addFDroidService
import javax.jmdns.ServiceInfo; //导入依赖的package包/类
/**
* Broadcasts the fact that a Bonjour peer was found to swap with.
* Checks that the service is an F-Droid service, and also that it is not the F-Droid service
* for this device (by comparing its signing fingerprint to our signing fingerprint).
*/
private void addFDroidService(ServiceInfo serviceInfo) {
final String type = serviceInfo.getPropertyString("type");
final String fingerprint = serviceInfo.getPropertyString("fingerprint");
final boolean isFDroid = type != null && type.startsWith("fdroidrepo");
final boolean isSelf = FDroidApp.repo != null && fingerprint != null && fingerprint.equalsIgnoreCase(FDroidApp.repo.fingerprint);
if (isFDroid && !isSelf) {
Utils.debugLog(TAG, "Found F-Droid swap Bonjour service:\n" + serviceInfo);
subscriber.onNext(new BonjourPeer(serviceInfo));
} else {
if (isSelf) {
Utils.debugLog(TAG, "Ignoring Bonjour service because it belongs to this device:\n" + serviceInfo);
} else {
Utils.debugLog(TAG, "Ignoring Bonjour service because it doesn't look like an F-Droid swap repo:\n" + serviceInfo);
}
}
}
示例3: Zeroconf
import javax.jmdns.ServiceInfo; //导入依赖的package包/类
public Zeroconf() {
/********************
* Variables
*******************/
this.jmmdns = JmmDNS.Factory.getInstance();
this.listeners = new HashSet<String>();
this.services = new HashSet<ServiceInfo>();
this.logger = new DefaultLogger();
this.listener_callbacks = new HashMap<String, ZeroconfDiscoveryHandler>();
this.default_listener_callback = null;
/********************
* Methods
*******************/
// be nice to get rid of this completely - and have it in the jmdns library itself.
this.jmmdns.addNetworkTopologyListener(this);
}
示例4: serviceResolved
import javax.jmdns.ServiceInfo; //导入依赖的package包/类
@Override
/**
* This implements service resolved in a very simple way. If the user has callbacks, then
* it just directly resolves the service info to a ros service info. Note that if you have
* multiple interfaces (e.g. eth0, wlan0) then this won't provide the resolved artifact
* for all interfaces. It might be worth adding a check for that service across all
* interfaces here and providing a fully updated (with regards to addresses) ros
* service info artifact to the user's callback here.
*/
public void serviceResolved(ServiceEvent event) {
final ServiceInfo service_info = event.getInfo();
ZeroconfDiscoveryHandler callback = listener_callbacks.get(service_info.getType());
if ( callback != null ) {
callback.serviceResolved(toDiscoveredService(service_info));
} else {
logger.println("[=] Resolved : " + service_info.getQualifiedName());
logger.println(" Port : " + service_info.getPort() );
for ( int i = 0; i < service_info.getInetAddresses().length; ++i ) {
logger.println(" Address : " + service_info.getInetAddresses()[i].getHostAddress() );
}
}
}
示例5: inetAddressRemoved
import javax.jmdns.ServiceInfo; //导入依赖的package包/类
@Override
public void inetAddressRemoved(NetworkTopologyEvent event) {
String event_address_str = event.getInetAddress().getHostAddress();
// can't get the display name like above, as the interface is no longer available.
// if we really want the display name, need to store it somewhere when the network interface
// is added.
logger.println("[-] NetworkInterface: " + event_address_str);
// Trigger service info callbacks - this is fairly brutal. It might be better to
// check here if that service is no longer supplied on all interfaces, then call
// serviceRemoved. If it is still supplied, provide a serviceResolved callback with
// the updated addresses.
event.getDNS().removeServiceTypeListener(this);
for(String listener : listeners ) {
logger.println(" Removing service listener '" + listener + "'");
event.getDNS().removeServiceListener(listener, this);
}
for (ServiceInfo service : services ) {
logger.println("Unpublishing Service:");
logger.println(" Name : " + service.getName() );
logger.println(" Type : " + service.getType() );
logger.println(" Port : " + service.getPort() );
event.getDNS().unregisterService(service); // this may not work because we're cloning it.
}
}
示例6: addFDroidService
import javax.jmdns.ServiceInfo; //导入依赖的package包/类
/**
* Broadcasts the fact that a Bonjour peer was found to swap with.
* Checks that the service is an F-Droid service, and also that it is not the F-Droid service
* for this device (by comparing its signing fingerprint to our signing fingerprint).
*/
private void addFDroidService(ServiceInfo serviceInfo) {
final String type = serviceInfo.getPropertyString("type");
final String fingerprint = serviceInfo.getPropertyString("fingerprint");
final boolean isFDroid = type != null && type.startsWith("fdroidrepo");
final boolean isSelf = FDroidApp.REPO != null && fingerprint != null && fingerprint.equalsIgnoreCase(FDroidApp.REPO.fingerprint);
if (isFDroid && !isSelf) {
Utils.debugLog(TAG, "Found F-Droid swap Bonjour service:\n" + serviceInfo);
subscriber.onNext(new BonjourPeer(serviceInfo));
} else {
if (isSelf) {
Utils.debugLog(TAG, "Ignoring Bonjour service because it belongs to this device:\n" + serviceInfo);
} else {
Utils.debugLog(TAG, "Ignoring Bonjour service because it doesn't look like an F-Droid swap repo:\n" + serviceInfo);
}
}
}
示例7: waitForInfoData
import javax.jmdns.ServiceInfo; //导入依赖的package包/类
private void waitForInfoData(ServiceInfo info, long timeout) {
synchronized (info) {
long loops = (timeout / 200L);
if (loops < 1) {
loops = 1;
}
for (int i = 0; i < loops; i++) {
if (info.hasData()) {
break;
}
try {
info.wait(200);
} catch (final InterruptedException e) {
/* Stub */
}
}
}
}
示例8: unregisterService
import javax.jmdns.ServiceInfo; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void unregisterService(ServiceInfo infoAbstract) {
final ServiceInfoImpl info = (ServiceInfoImpl) _services.get(infoAbstract.getKey());
if (info != null) {
info.cancelState();
this.startCanceler();
info.waitForCanceled(DNSConstants.CLOSE_TIMEOUT);
_services.remove(info.getKey(), info);
if (logger.isLoggable(Level.FINE)) {
logger.fine("unregisterService() JmDNS " + this.getName() + " unregistered service as " + info);
}
} else {
logger.warning(this.getName() + " removing unregistered service info: " + infoAbstract.getKey());
}
}
示例9: serviceAdded
import javax.jmdns.ServiceInfo; //导入依赖的package包/类
/**
* A service has been added.
*
* @param event
* service event
*/
@Override
public void serviceAdded(ServiceEvent event) {
synchronized (this) {
ServiceInfo info = event.getInfo();
if ((info != null) && (info.hasData())) {
_infos.put(event.getName(), info);
} else {
String subtype = (info != null ? info.getSubtype() : "");
info = ((JmDNSImpl) event.getDNS()).resolveServiceInfo(event.getType(), event.getName(), subtype, true);
if (info != null) {
_infos.put(event.getName(), info);
} else {
_events.put(event.getName(), event);
}
}
}
}
示例10: list
import javax.jmdns.ServiceInfo; //导入依赖的package包/类
/**
* Returns an array of all service infos which have been collected by this ServiceCollector.
*
* @param timeout
* timeout if the info list is empty.
* @return Service Info array
*/
public ServiceInfo[] list(long timeout) {
if (_infos.isEmpty() || !_events.isEmpty() || _needToWaitForInfos) {
long loops = (timeout / 200L);
if (loops < 1) {
loops = 1;
}
for (int i = 0; i < loops; i++) {
try {
Thread.sleep(200);
} catch (final InterruptedException e) {
/* Stub */
}
if (_events.isEmpty() && !_infos.isEmpty() && !_needToWaitForInfos) {
break;
}
}
}
_needToWaitForInfos = false;
return _infos.values().toArray(new ServiceInfo[_infos.size()]);
}
示例11: serviceResolved
import javax.jmdns.ServiceInfo; //导入依赖的package包/类
/**
* A service has been resolved. Its details are now available in the ServiceInfo record.<br/>
* <b>Note:</b>This call back will never be called if the service does not resolve.<br/>
*
* @param event
* The ServiceEvent providing the name, the fully qualified type of the service, and the service info record.
*/
synchronized void serviceResolved(ServiceEvent event) {
ServiceInfo info = event.getInfo();
if ((info != null) && (info.hasData())) {
String qualifiedName = event.getName() + "." + event.getType();
ServiceInfo previousServiceInfo = _addedServices.get(qualifiedName);
if (!_sameInfo(info, previousServiceInfo)) {
if (null == previousServiceInfo) {
if (null == _addedServices.putIfAbsent(qualifiedName, info.clone())) {
this.getListener().serviceResolved(event);
}
} else {
if (_addedServices.replace(qualifiedName, previousServiceInfo, info.clone())) {
this.getListener().serviceResolved(event);
}
}
} else {
logger.finer("Service Resolved called for a service already resolved: " + event);
}
} else {
logger.warning("Service Resolved called for an unresolved event: " + event);
}
}
示例12: JmmDNSImpl
import javax.jmdns.ServiceInfo; //导入依赖的package包/类
/**
*
*/
public JmmDNSImpl() {
super();
_networkListeners = Collections.synchronizedSet(new HashSet<NetworkTopologyListener>());
_knownMDNS = new ConcurrentHashMap<InetAddress, JmDNS>();
_services = new ConcurrentHashMap<String, ServiceInfo>(20);
_ListenerExecutor = Executors.newSingleThreadExecutor();
_jmDNSExecutor = Executors.newCachedThreadPool();
_timer = new Timer("Multihommed mDNS.Timer", true);
_serviceListeners = new ConcurrentHashMap<String, List<ServiceListener>>();
_typeListeners = Collections.synchronizedSet(new HashSet<ServiceTypeListener>());
_serviceTypes = Collections.synchronizedSet(new HashSet<String>());
(new NetworkChecker(this, NetworkTopologyDiscovery.Factory.getInstance())).start(_timer);
_isClosing = new AtomicBoolean(false);
_closed = new AtomicBoolean(false);
}
示例13: handleResponse
import javax.jmdns.ServiceInfo; //导入依赖的package包/类
/**
* Does the necessary actions, when this as a response.
*/
@Override
boolean handleResponse(JmDNSImpl dns) {
if (dns.getLocalHost().conflictWithRecord(this)) {
logger1.finer("handleResponse() Denial detected");
if (dns.isProbing()) {
dns.getLocalHost().incrementHostName();
dns.getCache().clear();
for (ServiceInfo serviceInfo : dns.getServices().values()) {
ServiceInfoImpl info = (ServiceInfoImpl) serviceInfo;
info.revertState();
}
}
dns.revertState();
return true;
}
return false;
}
示例14: getServiceEvent
import javax.jmdns.ServiceInfo; //导入依赖的package包/类
@Override
public ServiceEvent getServiceEvent(JmDNSImpl dns) {
ServiceInfo info = this.getServiceInfo(false);
((ServiceInfoImpl) info).setDns(dns);
// String domainName = "";
// String serviceName = this.getServer();
// int index = serviceName.indexOf('.');
// if (index > 0)
// {
// serviceName = this.getServer().substring(0, index);
// if (index + 1 < this.getServer().length())
// domainName = this.getServer().substring(index + 1);
// }
// return new ServiceEventImpl(dns, domainName, serviceName, info);
return new ServiceEventImpl(dns, info.getType(), info.getName(), info);
}
示例15: addFDroidService
import javax.jmdns.ServiceInfo; //导入依赖的package包/类
/**
* Broadcasts the fact that a Bonjour peer was found to swap with.
* Checks that the service is an F-Droid service, and also that it is not the F-Droid service
* for this device (by comparing its signing fingerprint to our signing fingerprint).
*/
private void addFDroidService(ServiceInfo serviceInfo) {
final String type = serviceInfo.getPropertyString("type");
final String fingerprint = serviceInfo.getPropertyString("fingerprint");
final boolean isFDroid = type != null && type.startsWith("fdroidrepo");
final boolean isSelf = FDroidApp.repo != null && fingerprint != null && fingerprint.equalsIgnoreCase(FDroidApp.repo.fingerprint);
if (isFDroid && !isSelf) {
Utils.debugLog(TAG, "Found F-Droid swap Bonjour service:\n" + serviceInfo);
foundPeer(new BonjourPeer(serviceInfo));
} else {
if (isSelf) {
Utils.debugLog(TAG, "Ignoring Bonjour service because it belongs to this device:\n" + serviceInfo);
} else {
Utils.debugLog(TAG, "Ignoring Bonjour service because it doesn't look like an F-Droid swap repo:\n" + serviceInfo);
}
}
}