1 10 11 package org.mule.routing.inbound; 12 13 import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList; 14 15 import java.io.Serializable ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 19 import org.mule.umo.UMOEvent; 20 21 25 public class EventGroup implements Serializable 27 { 28 31 private static final long serialVersionUID = -7337182983687406403L; 32 33 private final Object groupId; 34 private final List events; 35 private final long created; 36 private final int expectedSize; 37 38 public EventGroup(Object groupId) 39 { 40 this(groupId, -1); 41 } 42 43 public EventGroup(Object groupId, int expectedSize) 44 { 45 super(); 46 this.created = System.currentTimeMillis(); 47 this.events = new CopyOnWriteArrayList(); 48 this.expectedSize = expectedSize; 49 this.groupId = groupId; 50 } 51 52 public Object getGroupId() 53 { 54 return groupId; 55 } 56 57 public Iterator iterator() 58 { 59 return events.iterator(); 60 } 61 62 public void addEvent(UMOEvent event) 63 { 64 events.add(event); 65 } 66 67 public void removeEvent(UMOEvent event) 68 { 69 events.remove(event); 70 } 71 72 public long getCreated() 73 { 74 return created; 75 } 76 77 public int size() 78 { 79 return events.size(); 80 } 81 82 public void clear() 83 { 84 events.clear(); 85 } 86 87 public int expectedSize() 88 { 89 return expectedSize; 90 } 91 92 public String toString() 93 { 94 StringBuffer buf = new StringBuffer (80); 95 buf.append("Event Group Id=").append(groupId); 96 buf.append(", expected size=").append(expectedSize); 97 98 synchronized (events) 103 { 104 int currentSize = events.size(); 105 buf.append(", current events=").append(currentSize); 106 107 if (currentSize > 0) 108 { 109 buf.append(" ["); 110 Iterator i = events.iterator(); 111 while (i.hasNext()) 112 { 113 UMOEvent event = (UMOEvent)i.next(); 114 buf.append(event.getMessage().getUniqueId()); 115 if (i.hasNext()) 116 { 117 buf.append(", "); 118 } 119 } 120 buf.append(']'); 121 } 122 return buf.toString(); 123 } 124 } 125 126 } 127 | Popular Tags |