本文整理汇总了Java中javax.jmdns.ServiceEvent类的典型用法代码示例。如果您正苦于以下问题:Java ServiceEvent类的具体用法?Java ServiceEvent怎么用?Java ServiceEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServiceEvent类属于javax.jmdns包,在下文中一共展示了ServiceEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serviceResolved
import javax.jmdns.ServiceEvent; //导入依赖的package包/类
@Override
public void serviceResolved(ServiceEvent service) {
Log.i(TAG, "serviceResolved " + service);
if (service.getInfo().getNiceTextString().contains(SMARTCONFIG_IDENTIFIER)){
JSONObject deviceJSON = new JSONObject();
try {
deviceJSON.put("name", service.getName());
deviceJSON.put("host", service.getInfo().getHostAddresses()[0]);
deviceJSON.put("age", 0);
Log.i(TAG, "Publishing device found to application, name: " + service.getName());
callback.onDeviceResolved(deviceJSON);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
示例2: serviceRemoved
import javax.jmdns.ServiceEvent; //导入依赖的package包/类
@Override
public void serviceRemoved(ServiceEvent ev) {
@SuppressWarnings("deprecation")
String uuid = ev.getInfo().getHostAddress();
final ServiceDescription service = foundServices.get(uuid);
if (service != null) {
Util.runOnUI(new Runnable() {
@Override
public void run() {
for (DiscoveryProviderListener listener : serviceListeners) {
listener.onServiceRemoved(ZeroconfDiscoveryProvider.this, service);
}
}
});
}
}
示例3: testServiceResolveEventWhenThereIsFoundService
import javax.jmdns.ServiceEvent; //导入依赖的package包/类
@Test
public void testServiceResolveEventWhenThereIsFoundService() throws Exception {
// given
String uuid = "192.168.0.1";
String name = "Test TV";
ServiceDescription serviceDescription = new ServiceDescription("_testservicetype._tcp.local.", uuid, uuid);
serviceDescription.setFriendlyName(name);
ServiceEvent event = createMockedServiceEvent(uuid, name);
dp.foundServices.put(uuid, serviceDescription);
DiscoveryProviderListener listener = mock(DiscoveryProviderListener.class);
dp.addListener(listener);
// when
dp.jmdnsListener.serviceResolved(event);
// then
verify(listener, never()).onServiceAdded(any(DiscoveryProvider.class), any(ServiceDescription.class));
}
示例4: testServiceRemoveEvent
import javax.jmdns.ServiceEvent; //导入依赖的package包/类
@Test
public void testServiceRemoveEvent() throws Exception {
// given
String uuid = "192.168.0.1";
String name = "Test TV";
ServiceDescription serviceDescription = new ServiceDescription("_testservicetype._tcp.local.", uuid, uuid);
serviceDescription.setFriendlyName(name);
ServiceEvent event = createMockedServiceEvent(uuid, name);
DiscoveryProviderListener listener = mock(DiscoveryProviderListener.class);
dp.addListener(listener);
dp.foundServices.put(uuid, serviceDescription);
// when
dp.jmdnsListener.serviceRemoved(event);
Robolectric.runUiThreadTasksIncludingDelayedTasks();
// then
verify(listener).onServiceRemoved(any(DiscoveryProvider.class), any(ServiceDescription.class));
}
示例5: onResume
import javax.jmdns.ServiceEvent; //导入依赖的package包/类
@Override
public void onResume() {
super.onResume();
scanner = new Scanner(getContext());
scanner.setServerDiscoveryListener(new Scanner.DiscoveryListener() {
@Override
public void onUpdate(final List<ServiceEvent> services) {
Log.d(TAG, "Adding " + services.size() + " services");
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
adapter.setServices(services);
}
});
}
});
scanner.startScan();
}
示例6: serviceRemoved
import javax.jmdns.ServiceEvent; //导入依赖的package包/类
@Override
public void serviceRemoved(ServiceEvent event) {
if (event.getInfo() == null) {
// silent
return;
}
String name = event.getInfo().getName();
if (StringUtils.isEmpty(name)) {
name = renderer.getConfName();
}
ArrayList<ChromeDevice> devices = new ArrayList<>();
for (ChromeDevice device : chromeCasts) {
if (name.equals(device.getRendererName())) {
// Make the icon grey and delete after 5 seconds
device.delete(5000);
LOGGER.debug("Chromecast \"{}\" is gone.", name);
continue;
}
devices.add(device);
}
chromeCasts = devices;
}
示例7: serviceResolved
import javax.jmdns.ServiceEvent; //导入依赖的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() );
}
}
}
示例8: handleServiceResolved
import javax.jmdns.ServiceEvent; //导入依赖的package包/类
void handleServiceResolved(ServiceEvent event) {
List<ServiceListenerStatus> list = _serviceListeners.get(event.getType().toLowerCase());
final List<ServiceListenerStatus> listCopy;
if ((list != null) && (!list.isEmpty())) {
if ((event.getInfo() != null) && event.getInfo().hasData()) {
final ServiceEvent localEvent = event;
synchronized (list) {
listCopy = new ArrayList<ServiceListenerStatus>(list);
}
for (final ServiceListenerStatus listener : listCopy) {
_executor.submit(new Runnable() {
/** {@inheritDoc} */
@Override
public void run() {
listener.serviceResolved(localEvent);
}
});
}
}
}
}
示例9: serviceAdded
import javax.jmdns.ServiceEvent; //导入依赖的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: serviceResolved
import javax.jmdns.ServiceEvent; //导入依赖的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);
}
}
示例11: getServiceEvent
import javax.jmdns.ServiceEvent; //导入依赖的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);
}
示例12: serviceAdded
import javax.jmdns.ServiceEvent; //导入依赖的package包/类
@Override
public void serviceAdded(final ServiceEvent event) {
// TODO: Get clarification, but it looks like this is:
// 1) Identifying that there is _a_ bonjour service available
// 2) Adding it to the list to give some sort of feedback to the user
// 3) Requesting more detailed info in an async manner
// 4) If that is in fact an fdroid repo (after requesting info), then add it again
// so that more detailed info can be shown to the user.
//
// If so, when is the old one removed?
addFDroidService(event.getInfo());
// The member variable is likely to get set to null if a swap process starts, thus we hold
// a reference for the benefit of the background task so it doesn't have to synchronoize on it.
final JmDNS mdns = jmdns;
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
mdns.requestServiceInfo(event.getType(), event.getName(), true);
return null;
}
}.execute();
}
示例13: serviceAdded
import javax.jmdns.ServiceEvent; //导入依赖的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);
}
}
}
}
示例14: serviceAdded
import javax.jmdns.ServiceEvent; //导入依赖的package包/类
/**
* A service has been added.<br/>
* <b>Note:</b>This event is only the service added event. The service info associated with this event does not include resolution information.<br/>
* To get the full resolved information you need to listen to {@link #serviceResolved(javax.jmdns.ServiceEvent)} or call {@link javax.jmdns.JmDNS#getServiceInfo(String, String, long)}
*
* <pre>
* ServiceInfo info = event.getDNS().getServiceInfo(event.getType(), event.getName())
* </pre>
* <p>
* Please note that service resolution may take a few second to resolve.
* </p>
*
* @param event
* The ServiceEvent providing the name and fully qualified type of the service.
*/
void serviceAdded(ServiceEvent event)
{
String qualifiedName = event.getName() + "." + event.getType();
if (null == _addedServices.putIfAbsent(qualifiedName, (ServiceInfo) event.getInfo().clone()))
{
this.getListener().serviceAdded(event);
ServiceInfo info = event.getInfo();
if ((info != null) && (info.hasData()))
{
this.getListener().serviceResolved(event);
}
}
else
{
logger.finer("Service Added called for a service already added: " + event);
}
}
示例15: getServiceEvent
import javax.jmdns.ServiceEvent; //导入依赖的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);
}