Search in sources :

Example 1 with ServiceTypeListenerStatus

use of javax.jmdns.impl.ListenerStatus.ServiceTypeListenerStatus in project JAirPort by froks.

the class JmDNSImpl method addServiceTypeListener.

/**
     * {@inheritDoc}
     */
@Override
public void addServiceTypeListener(ServiceTypeListener listener) throws IOException {
    ServiceTypeListenerStatus status = new ServiceTypeListenerStatus(listener, ListenerStatus.ASYNCHONEOUS);
    _typeListeners.add(status);
    // report cached service types
    for (String type : _serviceTypes.keySet()) {
        status.serviceTypeAdded(new ServiceEventImpl(this, type, "", null));
    }
    this.startTypeResolver();
}
Also used : ServiceTypeListenerStatus(javax.jmdns.impl.ListenerStatus.ServiceTypeListenerStatus)

Example 2 with ServiceTypeListenerStatus

use of javax.jmdns.impl.ListenerStatus.ServiceTypeListenerStatus in project JAirPort by froks.

the class JmDNSImpl method removeServiceTypeListener.

/**
     * {@inheritDoc}
     */
@Override
public void removeServiceTypeListener(ServiceTypeListener listener) {
    ServiceTypeListenerStatus status = new ServiceTypeListenerStatus(listener, ListenerStatus.ASYNCHONEOUS);
    _typeListeners.remove(status);
}
Also used : ServiceTypeListenerStatus(javax.jmdns.impl.ListenerStatus.ServiceTypeListenerStatus)

Example 3 with ServiceTypeListenerStatus

use of javax.jmdns.impl.ListenerStatus.ServiceTypeListenerStatus in project JAirPort by froks.

the class JmDNSImpl method registerServiceType.

/**
     * {@inheritDoc}
     */
@Override
public boolean registerServiceType(String type) {
    boolean typeAdded = false;
    Map<Fields, String> map = ServiceInfoImpl.decodeQualifiedNameMapForType(type);
    String domain = map.get(Fields.Domain);
    String protocol = map.get(Fields.Protocol);
    String application = map.get(Fields.Application);
    String subtype = map.get(Fields.Subtype);
    final String name = (application.length() > 0 ? "_" + application + "." : "") + (protocol.length() > 0 ? "_" + protocol + "." : "") + domain + ".";
    final String loname = name.toLowerCase();
    if (logger.isLoggable(Level.FINE)) {
        logger.fine(this.getName() + ".registering service type: " + type + " as: " + name + (subtype.length() > 0 ? " subtype: " + subtype : ""));
    }
    if (!_serviceTypes.containsKey(loname) && !application.toLowerCase().equals("dns-sd") && !domain.toLowerCase().endsWith("in-addr.arpa") && !domain.toLowerCase().endsWith("ip6.arpa")) {
        typeAdded = _serviceTypes.putIfAbsent(loname, new ServiceTypeEntry(name)) == null;
        if (typeAdded) {
            final ServiceTypeListenerStatus[] list = _typeListeners.toArray(new ServiceTypeListenerStatus[_typeListeners.size()]);
            final ServiceEvent event = new ServiceEventImpl(this, name, "", null);
            for (final ServiceTypeListenerStatus status : list) {
                _executor.submit(new Runnable() {

                    /** {@inheritDoc} */
                    @Override
                    public void run() {
                        status.serviceTypeAdded(event);
                    }
                });
            }
        }
    }
    if (subtype.length() > 0) {
        ServiceTypeEntry subtypes = _serviceTypes.get(loname);
        if ((subtypes != null) && (!subtypes.contains(subtype))) {
            synchronized (subtypes) {
                if (!subtypes.contains(subtype)) {
                    typeAdded = true;
                    subtypes.add(subtype);
                    final ServiceTypeListenerStatus[] list = _typeListeners.toArray(new ServiceTypeListenerStatus[_typeListeners.size()]);
                    final ServiceEvent event = new ServiceEventImpl(this, "_" + subtype + "._sub." + name, "", null);
                    for (final ServiceTypeListenerStatus status : list) {
                        _executor.submit(new Runnable() {

                            /** {@inheritDoc} */
                            @Override
                            public void run() {
                                status.subTypeForServiceTypeAdded(event);
                            }
                        });
                    }
                }
            }
        }
    }
    return typeAdded;
}
Also used : Fields(javax.jmdns.ServiceInfo.Fields) ServiceEvent(javax.jmdns.ServiceEvent) ServiceTypeListenerStatus(javax.jmdns.impl.ListenerStatus.ServiceTypeListenerStatus)

Aggregations

ServiceTypeListenerStatus (javax.jmdns.impl.ListenerStatus.ServiceTypeListenerStatus)3 ServiceEvent (javax.jmdns.ServiceEvent)1 Fields (javax.jmdns.ServiceInfo.Fields)1