@Override public synchronized void addItemUpdateListener ( final String itemName, final ItemUpdateListener listener ) { logger.debug ( "Adding item update listener - itemId: {}, listener: {}", itemName, listener ); ItemSyncController controller = this.itemListeners.get ( itemName ); if ( controller == null ) { controller = new ItemSyncController ( this.connection, this, itemName ); this.itemListeners.put ( itemName, controller ); } controller.add ( listener ); }
public synchronized void disconnect () { notifySubscriptionChange ( SubscriptionState.DISCONNECTED, null ); notifyDataChange ( Variant.NULL, Collections.<String, Variant> emptyMap (), true ); } }
@Override public synchronized void removeItemUpdateListener ( final String itemName, final ItemUpdateListener listener ) { logger.debug ( "Removing item update listener - itemId: {}, listener: {}", itemName, listener ); if ( itemName == null ) { return; } final ItemSyncController controller = this.itemListeners.get ( itemName ); if ( controller != null ) { controller.remove ( listener ); } }
public synchronized void sync ( final boolean force ) { final boolean subscribe = !this.listeners.isEmpty (); if ( this.subscribed == subscribe && !force ) { // nothing to do return; } if ( subscribe ) { subscribe (); } else { unsubscribe (); } }
public synchronized void remove ( final ItemUpdateListener listener ) { final ListenerInfo result = this.listeners.remove ( listener ); if ( result != null ) { sync ( false ); } }
private synchronized void handleError ( final Throwable e ) { logger.warn ( "Failed to change subscription state", e ); this.subscribed = false; notifySubscriptionChange ( SubscriptionState.DISCONNECTED, e ); }
protected synchronized void disconnectAllItems () { logger.debug ( "Disconnecting all items" ); for ( final Map.Entry<String, ItemSyncController> entry : this.itemListeners.entrySet () ) { entry.getValue ().disconnect (); } logger.debug ( "Disconnecting all items: complete" ); }
protected synchronized void subscribe () { try { logger.debug ( "Syncing listen state: active" ); this.subscribed = true; this.connection.subscribeItem ( this.itemId ); } catch ( final Throwable e ) { handleError ( e ); } }
public synchronized void sync ( final boolean force ) { final boolean subscribe = !this.listeners.isEmpty (); if ( this.subscribed == subscribe && !force ) { // nothing to do return; } if ( subscribe ) { subscribe (); } else { unsubscribe (); } }
public synchronized void remove ( final ItemUpdateListener listener ) { final ListenerInfo result = this.listeners.remove ( listener ); if ( result != null ) { sync ( false ); } }
private synchronized void handleError ( final Throwable e ) { logger.warn ( "Failed to change subscription state", e ); this.subscribed = false; notifySubscriptionChange ( SubscriptionState.DISCONNECTED, e ); }
protected synchronized void disconnectAllItems () { logger.debug ( "Disconnecting all items" ); for ( final Map.Entry<String, ItemSyncController> entry : this.itemListeners.entrySet () ) { entry.getValue ().disconnect (); } logger.debug ( "Disconnecting all items: complete" ); }
protected synchronized void subscribe () { try { logger.debug ( "Syncing listen state: active" ); this.subscribed = true; this.connection.subscribeItem ( this.itemId ); } catch ( final Throwable e ) { handleError ( e ); } }
public synchronized void disconnect () { notifySubscriptionChange ( SubscriptionState.DISCONNECTED, null ); notifyDataChange ( Variant.NULL, Collections.<String, Variant> emptyMap (), true ); } }
@Override public synchronized void addItemUpdateListener ( final String itemName, final ItemUpdateListener listener ) { logger.debug ( "Adding item update listener - itemId: {}, listener: {}", itemName, listener ); ItemSyncController controller = this.itemListeners.get ( itemName ); if ( controller == null ) { controller = new ItemSyncController ( this.connection, this, itemName ); this.itemListeners.put ( itemName, controller ); } controller.add ( listener ); }
/** * Synchronized all items that are currently known */ protected synchronized void resyncAllItems () { logger.debug ( "Syncing all items ({})", this.itemListeners.size () ); for ( final Map.Entry<String, ItemSyncController> entry : this.itemListeners.entrySet () ) { entry.getValue ().sync ( true ); } logger.debug ( "re-sync complete" ); }
protected synchronized void unsubscribe () { try { logger.debug ( "Syncing listen state: inactive" ); this.subscribed = false; this.cachedValue = null; this.cachedAttributes.clear (); notifySubscriptionChange ( SubscriptionState.DISCONNECTED, null ); this.connection.unsubscribeItem ( this.itemId ); } catch ( final Throwable e ) { logger.warn ( "Failed to handle unsubscribe", e ); } }
@Override public synchronized void removeItemUpdateListener ( final String itemName, final ItemUpdateListener listener ) { logger.debug ( "Removing item update listener - itemId: {}, listener: {}", itemName, listener ); if ( itemName == null ) { return; } final ItemSyncController controller = this.itemListeners.get ( itemName ); if ( controller != null ) { controller.remove ( listener ); } }
/** * Synchronized all items that are currently known */ protected synchronized void resyncAllItems () { logger.debug ( "Syncing all items ({})", this.itemListeners.size () ); for ( final Map.Entry<String, ItemSyncController> entry : this.itemListeners.entrySet () ) { entry.getValue ().sync ( true ); } logger.debug ( "re-sync complete" ); }
protected synchronized void unsubscribe () { try { logger.debug ( "Syncing listen state: inactive" ); this.subscribed = false; this.cachedValue = null; this.cachedAttributes.clear (); notifySubscriptionChange ( SubscriptionState.DISCONNECTED, null ); this.connection.unsubscribeItem ( this.itemId ); } catch ( final Throwable e ) { logger.warn ( "Failed to handle unsubscribe", e ); } }