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.NotifyPublishOperations; 33 34 38 39 public class OfferManager extends EventTypeSet implements NotifyPublishOperations 40 { 41 public static final OfferManager NULL_MANAGER = new OfferManager(Collections.EMPTY_LIST); 42 43 private final List listeners_; 44 45 private final Logger logger_ = LogUtil.getLogger(getClass().getName()); 46 47 public OfferManager() 48 { 49 this(new ArrayList ()); 50 } 51 52 private OfferManager(List list) 53 { 54 listeners_ = list; 55 } 56 57 59 public void addListener(NotifyPublishOperations listener) 60 { 61 synchronized (listeners_) 62 { 63 listeners_.add(listener); 64 } 65 } 66 67 public void removeListener(NotifyPublishOperations 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(); 83 84 while (_i.hasNext()) 85 { 86 NotifyPublishOperations _listener = (NotifyPublishOperations) _i.next(); 87 88 try 89 { 90 _listener.offer_change(added, removed); 91 } catch (Exception e) 92 { 93 logger_.error("offer_change failed for " + _listener, e); 94 } 95 } 96 } 97 } 98 99 public void offer_change(EventType[] added, EventType[] removed) throws InvalidEventType 100 { 101 try 102 { 103 changeSet(added, removed); 104 } catch (InterruptedException e) 105 { 106 } 108 } 109 110 public EventType[] obtain_offered_types() 111 { 112 try 113 { 114 return getAllTypes(); 115 } catch (InterruptedException e) 116 { 117 return EMPTY_EVENT_TYPE; 118 } 119 } 120 } | Popular Tags |