public static void main(String[] args) throws Exception { System.out.println("Starting Cling..."); UpnpService upnpService = new UpnpServiceImpl(); long noOfDevices = args.length == 1 ? Long.valueOf(args[0]) : 10; System.out.println("Registering BinaryLight devices: " + noOfDevices); for (long i = 0; i <= noOfDevices; i++) { LocalService service = new AnnotationLocalServiceBinder().read(DemoBinaryLight.class); service.setManager(new DefaultServiceManager(service, DemoBinaryLight.class)); upnpService.getRegistry().addDevice( DemoBinaryLight.createDefaultDevice(UDN.uniqueSystemIdentifier(Long.toString(i)), "Device: " + i, service) ); } System.out.println("Completed device registration"); } }
protected void init() { log.fine("No service implementation instance available, initializing..."); try { // The actual instance we ware going to use and hold a reference to (1:1 instance for manager) serviceImpl = createServiceInstance(); // How the implementation instance will tell us about property changes propertyChangeSupport = createPropertyChangeSupport(serviceImpl); propertyChangeSupport.addPropertyChangeListener(createPropertyChangeListener(serviceImpl)); } catch (Exception ex) { throw new RuntimeException("Could not initialize implementation: " + ex, ex); } }
@Override public Collection<StateVariableValue> getCurrentState() throws Exception { lock(); try { Collection<StateVariableValue> values = readInitialEventedStateVariableValues(); if (values != null) { log.fine("Obtained initial state variable values for event, skipping individual state variable accessors"); return values; } values = new ArrayList<>(); for (StateVariable stateVariable : getService().getStateVariables()) { if (stateVariable.getEventDetails().isSendEvents()) { StateVariableAccessor accessor = getService().getAccessor(stateVariable); if (accessor == null) throw new IllegalStateException("No accessor for evented state variable"); values.add(accessor.read(stateVariable, getImplementation())); } } return values; } finally { unlock(); } }
@Override protected T createServiceInstance() throws Exception { final T serviceInstance = super.createServiceInstance(); beanFactory.autowireBean(serviceInstance); return serviceInstance; } }
protected T createServiceInstance() throws Exception { if (serviceClass == null) { throw new IllegalStateException("Subclass has to provide service class or override createServiceInstance()"); } try { // Use this constructor if possible return serviceClass.getConstructor(LocalService.class).newInstance(getService()); } catch (NoSuchMethodException ex) { log.fine("Creating new service implementation instance with no-arg constructor: " + serviceClass.getName()); return serviceClass.newInstance(); } }
protected void lock() { try { if (lock.tryLock(getLockTimeoutMillis(), TimeUnit.MILLISECONDS)) { if (log.isLoggable(Level.FINEST)) log.finest("Acquired lock"); } else { throw new RuntimeException("Failed to acquire lock in milliseconds: " + getLockTimeoutMillis()); } } catch (InterruptedException e) { throw new RuntimeException("Failed to acquire lock:" + e); } }
protected T createServiceInstance() throws Exception { if (serviceClass == null) { throw new IllegalStateException("Subclass has to provide service class or override createServiceInstance()"); } try { // Use this constructor if possible return serviceClass.getConstructor(LocalService.class).newInstance(getService()); } catch (NoSuchMethodException ex) { log.fine("Creating new service implementation instance with no-arg constructor: " + serviceClass.getName()); return serviceClass.newInstance(); } }
protected void lock() { try { if (lock.tryLock(getLockTimeoutMillis(), TimeUnit.MILLISECONDS)) { if (log.isLoggable(Level.FINEST)) log.finest("Acquired lock"); } else { throw new RuntimeException("Failed to acquire lock in milliseconds: " + getLockTimeoutMillis()); } } catch (InterruptedException e) { throw new RuntimeException("Failed to acquire lock:" + e); } }
protected Collection<StateVariableValue> getCurrentState(String[] variableNames) throws Exception { lock(); try { Collection<StateVariableValue> values = new ArrayList<>(); for (String variableName : variableNames) { variableName = variableName.trim(); StateVariable stateVariable = getService().getStateVariable(variableName); if (stateVariable == null || !stateVariable.getEventDetails().isSendEvents()) { log.fine("Ignoring unknown or non-evented state variable: " + variableName); continue; } StateVariableAccessor accessor = getService().getAccessor(stateVariable); if (accessor == null) { log.warning("Ignoring evented state variable without accessor: " + variableName); continue; } values.add(accessor.read(stateVariable, getImplementation())); } return values; } finally { unlock(); } }
protected LocalDevice createDevice() throws ValidationException, LocalServiceBindingException { DeviceType type = new UDADeviceType("BinaryLight", 1); DeviceDetails details = new DeviceDetails( "Friendly Binary Light", new ManufacturerDetails("ACME"), new ModelDetails("AndroidLight", "A light with on/off switch.", "v1") ); LocalService service = new AnnotationLocalServiceBinder().read(SwitchPower.class); service.setManager( new DefaultServiceManager<>(service, SwitchPower.class) ); return new LocalDevice( new DeviceIdentity(udn), type, details, createDefaultDeviceIcon(), service ); } // DOC:CREATE_DEVICE
protected void init() { log.fine("No service implementation instance available, initializing..."); try { // The actual instance we ware going to use and hold a reference to (1:1 instance for manager) serviceImpl = createServiceInstance(); // How the implementation instance will tell us about property changes propertyChangeSupport = createPropertyChangeSupport(serviceImpl); propertyChangeSupport.addPropertyChangeListener(createPropertyChangeListener(serviceImpl)); } catch (Exception ex) { throw new RuntimeException("Could not initialize implementation: " + ex, ex); } }
protected T createServiceInstance() throws Exception { if (serviceClass == null) { throw new IllegalStateException("Subclass has to provide service class or override createServiceInstance()"); } try { // Use this constructor if possible return serviceClass.getConstructor(LocalService.class).newInstance(getService()); } catch (NoSuchMethodException ex) { log.fine("Creating new service implementation instance with no-arg constructor: " + serviceClass.getName()); return serviceClass.newInstance(); } }
protected void lock() { try { if (lock.tryLock(getLockTimeoutMillis(), TimeUnit.MILLISECONDS)) { if (log.isLoggable(Level.FINEST)) log.finest("Acquired lock"); } else { throw new RuntimeException("Failed to acquire lock in milliseconds: " + getLockTimeoutMillis()); } } catch (InterruptedException e) { throw new RuntimeException("Failed to acquire lock:" + e); } }
@Override public Collection<StateVariableValue> getCurrentState() throws Exception { lock(); try { Collection<StateVariableValue> values = readInitialEventedStateVariableValues(); if (values != null) { log.fine("Obtained initial state variable values for event, skipping individual state variable accessors"); return values; } values = new ArrayList(); for (StateVariable stateVariable : getService().getStateVariables()) { if (stateVariable.getEventDetails().isSendEvents()) { StateVariableAccessor accessor = getService().getAccessor(stateVariable); if (accessor == null) throw new IllegalStateException("No accessor for evented state variable"); values.add(accessor.read(stateVariable, getImplementation())); } } return values; } finally { unlock(); } }
public MediaServer(InetAddress localAddress, Context ctx) throws ValidationException { super(null, port, null, true); Log.i(TAG, "Creating media server !"); localService = new AnnotationLocalServiceBinder() .read(ContentDirectoryService.class); localService.setManager(new DefaultServiceManager<ContentDirectoryService>( localService, ContentDirectoryService.class)); udn = UDN.valueOf(new UUID(0,10).toString()); this.localAddress = localAddress; this.ctx = ctx; createLocalDevice(); ContentDirectoryService contentDirectoryService = (ContentDirectoryService)localService.getManager().getImplementation(); contentDirectoryService.setContext(ctx); contentDirectoryService.setBaseURL(getAddress()); }
protected void init() { log.fine("No service implementation instance available, initializing..."); try { // The actual instance we ware going to use and hold a reference to (1:1 instance for manager) serviceImpl = createServiceInstance(); // How the implementation instance will tell us about property changes propertyChangeSupport = createPropertyChangeSupport(serviceImpl); propertyChangeSupport.addPropertyChangeListener(createPropertyChangeListener(serviceImpl)); } catch (Exception ex) { throw new RuntimeException("Could not initialize implementation: " + ex, ex); } }