1 package org.jacorb.notification; 2 3 22 23 import java.util.ArrayList ; 24 import java.util.Collections ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 28 import org.apache.avalon.framework.logger.Logger; 29 import org.jacorb.notification.util.LogUtil; 30 import org.omg.CosNotification.EventType; 31 import org.omg.CosNotifyComm.InvalidEventType; 32 import org.omg.CosNotifyComm.NotifySubscribeOperations; 33 34 38 39 public class SubscriptionManager extends EventTypeSet implements NotifySubscribeOperations 40 { 41 public static final SubscriptionManager NULL_MANAGER = new SubscriptionManager(Collections.EMPTY_LIST); 42 43 private final Logger logger_ = LogUtil.getLogger(getClass().getName()); 44 45 private final List listeners_; 46 47 public SubscriptionManager() 48 { 49 this(new ArrayList ()); 50 } 51 52 private SubscriptionManager(List list) 53 { 54 listeners_ = list; 55 } 56 57 59 public void addListener(NotifySubscribeOperations listener) 60 { 61 synchronized (listeners_) 62 { 63 listeners_.add(listener); 64 } 65 } 66 67 public void removeListener(NotifySubscribeOperations listener) 68 { 69 synchronized (listeners_) 70 { 71 listeners_.remove(listener); 72 } 73 } 74 75 public void actionSetChanged(EventType[] added, EventType[] removed) 76 { 77 synchronized (listeners_) 78 { 79 Iterator _i = new ArrayList (listeners_).iterator(); 84 85 while (_i.hasNext()) 86 { 87 NotifySubscribeOperations _listener = (NotifySubscribeOperations) _i.next(); 88 89 try 90 { 91 _listener.subscription_change(added, removed); 92 } catch (Exception e) 93 { 94 logger_.error("subscription_change failed for " + _listener, e); 95 } 96 } 97 } 98 } 99 100 public void subscription_change(EventType[] added, EventType[] removed) throws InvalidEventType 101 { 102 try 103 { 104 changeSet(added, removed); 105 } catch (InterruptedException e) 106 { 107 } 109 } 110 111 public EventType[] obtain_subscription_types() 112 { 113 try 114 { 115 return getAllTypes(); 116 } catch (InterruptedException e) 117 { 118 return EMPTY_EVENT_TYPE; 119 } 120 } 121 } | Popular Tags |