|
@@ -1,188 +1,188 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.eventbus.client.nonpublic; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.eventbus.client.*; |
5 |
|
- |
import org.litesoft.commonfoundation.iterators.*; |
6 |
|
- |
import org.litesoft.logger.*; |
7 |
|
- |
|
8 |
|
- |
import java.util.*; |
9 |
|
- |
|
10 |
|
- |
public class EventBusMessageCollector { |
11 |
|
- |
public EventBusMessageCollector( Logger pLogger ) { |
12 |
|
- |
// Local Group |
13 |
|
- |
mPublishedEvents = new LoggingEventList( pLogger, "publishEvent" ); |
14 |
|
- |
mSubscribes = new SubscriptionList( pLogger, "subscribe" ); |
15 |
|
- |
mUnsubscribes = new SubscriptionList( pLogger, "unsubscribe" ); |
16 |
|
- |
// Remote Group |
17 |
|
- |
mFromRemotePeerEvents = new LoggingEventList( pLogger, "fromRemotePeerEvent" ); |
18 |
|
- |
mAddRemotePeerInterests = new LoggingStringSet( pLogger, "addRemotePeerInterest" ); |
19 |
|
- |
mRemoveRemotePeerInterests = new LoggingStringSet( pLogger, "removeRemotePeerInterest" ); |
20 |
|
- |
mFromRemoteAckPeerInterests = new LoggingStringSet( pLogger, "fromRemoteAckPeerInterest" ); |
21 |
|
- |
} |
22 |
|
- |
|
23 |
|
- |
// Local Group |
24 |
|
- |
private LoggingEventList mPublishedEvents; |
25 |
|
- |
private SubscriptionList mSubscribes; |
26 |
|
- |
private SubscriptionList mUnsubscribes; |
27 |
|
- |
// Remote Group |
28 |
|
- |
private LoggingEventList mFromRemotePeerEvents; |
29 |
|
- |
private LoggingStringSet mAddRemotePeerInterests; |
30 |
|
- |
private LoggingStringSet mRemoveRemotePeerInterests; |
31 |
|
- |
private LoggingStringSet mFromRemoteAckPeerInterests; |
32 |
|
- |
|
33 |
|
- |
public String toString() { |
34 |
|
- |
StringBuilder sb = new StringBuilder( "EventBusMessageCollector:" ); |
35 |
|
- |
if ( isEmpty() ) { |
36 |
|
- |
sb.append( " Empty " ); |
37 |
|
- |
} else { |
38 |
|
- |
appendTo( sb, mPublishedEvents ); |
39 |
|
- |
appendTo( sb, mSubscribes ); |
40 |
|
- |
appendTo( sb, mUnsubscribes ); |
41 |
|
- |
appendTo( sb, mFromRemotePeerEvents ); |
42 |
|
- |
appendTo( sb, mAddRemotePeerInterests ); |
43 |
|
- |
appendTo( sb, mRemoveRemotePeerInterests ); |
44 |
|
- |
appendTo( sb, mFromRemoteAckPeerInterests ); |
45 |
|
- |
} |
46 |
|
- |
|
47 |
|
- |
return sb.toString(); |
48 |
|
- |
} |
49 |
|
- |
|
50 |
|
- |
private void appendTo( StringBuilder pSb, LoggingCollection pToAppend ) { |
51 |
|
- |
if ( !pToAppend.isEmpty() ) { |
52 |
|
- |
pSb.append( "\n " ).append( pToAppend ); |
53 |
|
- |
} |
54 |
|
- |
} |
55 |
|
- |
|
56 |
|
- |
public void clear() { |
57 |
|
- |
// Local Group |
58 |
|
- |
mPublishedEvents.clear(); |
59 |
|
- |
mSubscribes.clear(); |
60 |
|
- |
mUnsubscribes.clear(); |
61 |
|
- |
// Remote Group |
62 |
|
- |
mFromRemotePeerEvents.clear(); |
63 |
|
- |
mAddRemotePeerInterests.clear(); |
64 |
|
- |
mRemoveRemotePeerInterests.clear(); |
65 |
|
- |
mFromRemoteAckPeerInterests.clear(); |
66 |
|
- |
} |
67 |
|
- |
|
68 |
|
- |
public boolean isEmpty() { |
69 |
|
- |
return // Local Group |
70 |
|
- |
mPublishedEvents.isEmpty() && // |
71 |
|
- |
mSubscribes.isEmpty() && // |
72 |
|
- |
mUnsubscribes.isEmpty() && // |
73 |
|
- |
// Remote Group |
74 |
|
- |
mFromRemotePeerEvents.isEmpty() && // |
75 |
|
- |
mAddRemotePeerInterests.isEmpty() && // |
76 |
|
- |
mRemoveRemotePeerInterests.isEmpty() && // |
77 |
|
- |
mFromRemoteAckPeerInterests.isEmpty(); |
78 |
|
- |
} |
79 |
|
- |
|
80 |
|
- |
public void addSubscribes( EventSubscriptionStructure[] pSubscriptions ) { |
81 |
|
- |
mSubscribes.add( pSubscriptions ); |
82 |
|
- |
} |
83 |
|
- |
|
84 |
|
- |
public Iterator getSubscribes() { |
85 |
|
- |
return mSubscribes.iterator(); |
86 |
|
- |
} |
87 |
|
- |
|
88 |
|
- |
public void addUnsubscribes( EventSubscriptionStructure[] pSubscriptions ) { |
89 |
|
- |
mUnsubscribes.add( pSubscriptions ); |
90 |
|
- |
} |
91 |
|
- |
|
92 |
|
- |
public Iterator getUnsubscribes() { |
93 |
|
- |
return mUnsubscribes.iterator(); |
94 |
|
- |
} |
95 |
|
- |
|
96 |
|
- |
public void addPublishedEvent( EventPackage pPackage ) { |
97 |
|
- |
mPublishedEvents.add( pPackage ); |
98 |
|
- |
} |
99 |
|
- |
|
100 |
|
- |
public void addPublishedEvents( EventPackage[] pPackages ) { |
101 |
|
- |
mPublishedEvents.add( pPackages ); |
102 |
|
- |
} |
103 |
|
- |
|
104 |
|
- |
public Iterator getPublishedEvents() { |
105 |
|
- |
return mPublishedEvents.iterator(); |
106 |
|
- |
} |
107 |
|
- |
|
108 |
|
- |
public void addFromRemotePeerEvent( EventPackage pPackage ) { |
109 |
|
- |
mFromRemotePeerEvents.add( pPackage ); |
110 |
|
- |
} |
111 |
|
- |
|
112 |
|
- |
public void addFromRemotePeerEvents( EventPackage[] pPackages ) { |
113 |
|
- |
mFromRemotePeerEvents.add( pPackages ); |
114 |
|
- |
} |
115 |
|
- |
|
116 |
|
- |
public Iterator getFromRemotePeerEvents() { |
117 |
|
- |
return mFromRemotePeerEvents.iterator(); |
118 |
|
- |
} |
119 |
|
- |
|
120 |
|
- |
public void addRemotePeerInterests( String[] pInterests ) { |
121 |
|
- |
mAddRemotePeerInterests.add( pInterests ); |
122 |
|
- |
} |
123 |
|
- |
|
124 |
|
- |
public Set getAddRemotePeerInterests() { |
125 |
|
- |
return mAddRemotePeerInterests.getAndClearSet(); |
126 |
|
- |
} |
127 |
|
- |
|
128 |
|
- |
public void removeRemotePeerInterests( String[] pInterests ) { |
129 |
|
- |
mRemoveRemotePeerInterests.add( pInterests ); |
130 |
|
- |
} |
131 |
|
- |
|
132 |
|
- |
public Set getRemoveRemotePeerInterests() { |
133 |
|
- |
return mRemoveRemotePeerInterests.getAndClearSet(); |
134 |
|
- |
} |
135 |
|
- |
|
136 |
|
- |
public void addFromRemoteAckPeerInterests( String[] pInterests ) { |
137 |
|
- |
mFromRemoteAckPeerInterests.add( pInterests ); |
138 |
|
- |
} |
139 |
|
- |
|
140 |
|
- |
public Iterator getFromRemoteAckPeerInterests() { |
141 |
|
- |
return mFromRemoteAckPeerInterests.iterator(); |
142 |
|
- |
} |
143 |
|
- |
|
144 |
|
- |
public static class SubscriptionList implements LoggingCollection { |
145 |
|
- |
private List mMembers = new ArrayList(); |
146 |
|
- |
private Logger mLogger; |
147 |
|
- |
private String mLogText; |
148 |
|
- |
|
149 |
|
- |
public SubscriptionList( Logger pLogger, String pLogText ) { |
150 |
|
- |
mLogger = pLogger; |
151 |
|
- |
mLogText = pLogText; |
152 |
|
- |
} |
153 |
|
- |
|
154 |
|
- |
public void add( EventSubscriptionStructure[] pNewMembers ) { |
155 |
|
- |
if ( pNewMembers != null ) { |
156 |
|
- |
for ( int i = 0; i < pNewMembers.length; i++ ) { |
157 |
|
- |
add( pNewMembers[i] ); |
158 |
|
- |
} |
159 |
|
- |
} |
160 |
|
- |
} |
161 |
|
- |
|
162 |
|
- |
public void add( EventSubscriptionStructure pNewMember ) { |
163 |
|
- |
if ( pNewMember != null ) { |
164 |
|
- |
mLogger.trace.log( "(", mLogText, "):", pNewMember ); |
165 |
|
- |
mMembers.add( pNewMember ); |
166 |
|
- |
} |
167 |
|
- |
} |
168 |
|
- |
|
169 |
|
- |
@Override |
170 |
|
- |
public void clear() { |
171 |
|
- |
mMembers.clear(); |
172 |
|
- |
} |
173 |
|
- |
|
174 |
|
- |
@Override |
175 |
|
- |
public boolean isEmpty() { |
176 |
|
- |
return mMembers.isEmpty(); |
177 |
|
- |
} |
178 |
|
- |
|
179 |
|
- |
@Override |
180 |
|
- |
public Iterator iterator() { |
181 |
|
- |
return isEmpty() ? Iterators.empty() : mMembers.iterator(); |
182 |
|
- |
} |
183 |
|
- |
|
184 |
|
- |
public String toString() { |
185 |
|
- |
return mLogText + ":" + mMembers; |
186 |
|
- |
} |
187 |
|
- |
} |
188 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.eventbus.client.nonpublic; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.eventbus.client.*; |
|
5 |
+ |
import org.litesoft.commonfoundation.iterators.*; |
|
6 |
+ |
import org.litesoft.logger.*; |
|
7 |
+ |
|
|
8 |
+ |
import java.util.*; |
|
9 |
+ |
|
|
10 |
+ |
public class EventBusMessageCollector { |
|
11 |
+ |
public EventBusMessageCollector( Logger pLogger ) { |
|
12 |
+ |
// Local Group |
|
13 |
+ |
mPublishedEvents = new LoggingEventList( pLogger, "publishEvent" ); |
|
14 |
+ |
mSubscribes = new SubscriptionList( pLogger, "subscribe" ); |
|
15 |
+ |
mUnsubscribes = new SubscriptionList( pLogger, "unsubscribe" ); |
|
16 |
+ |
// Remote Group |
|
17 |
+ |
mFromRemotePeerEvents = new LoggingEventList( pLogger, "fromRemotePeerEvent" ); |
|
18 |
+ |
mAddRemotePeerInterests = new LoggingStringSet( pLogger, "addRemotePeerInterest" ); |
|
19 |
+ |
mRemoveRemotePeerInterests = new LoggingStringSet( pLogger, "removeRemotePeerInterest" ); |
|
20 |
+ |
mFromRemoteAckPeerInterests = new LoggingStringSet( pLogger, "fromRemoteAckPeerInterest" ); |
|
21 |
+ |
} |
|
22 |
+ |
|
|
23 |
+ |
// Local Group |
|
24 |
+ |
private LoggingEventList mPublishedEvents; |
|
25 |
+ |
private SubscriptionList mSubscribes; |
|
26 |
+ |
private SubscriptionList mUnsubscribes; |
|
27 |
+ |
// Remote Group |
|
28 |
+ |
private LoggingEventList mFromRemotePeerEvents; |
|
29 |
+ |
private LoggingStringSet mAddRemotePeerInterests; |
|
30 |
+ |
private LoggingStringSet mRemoveRemotePeerInterests; |
|
31 |
+ |
private LoggingStringSet mFromRemoteAckPeerInterests; |
|
32 |
+ |
|
|
33 |
+ |
public String toString() { |
|
34 |
+ |
StringBuilder sb = new StringBuilder( "EventBusMessageCollector:" ); |
|
35 |
+ |
if ( isEmpty() ) { |
|
36 |
+ |
sb.append( " Empty " ); |
|
37 |
+ |
} else { |
|
38 |
+ |
appendTo( sb, mPublishedEvents ); |
|
39 |
+ |
appendTo( sb, mSubscribes ); |
|
40 |
+ |
appendTo( sb, mUnsubscribes ); |
|
41 |
+ |
appendTo( sb, mFromRemotePeerEvents ); |
|
42 |
+ |
appendTo( sb, mAddRemotePeerInterests ); |
|
43 |
+ |
appendTo( sb, mRemoveRemotePeerInterests ); |
|
44 |
+ |
appendTo( sb, mFromRemoteAckPeerInterests ); |
|
45 |
+ |
} |
|
46 |
+ |
|
|
47 |
+ |
return sb.toString(); |
|
48 |
+ |
} |
|
49 |
+ |
|
|
50 |
+ |
private void appendTo( StringBuilder pSb, LoggingCollection pToAppend ) { |
|
51 |
+ |
if ( !pToAppend.isEmpty() ) { |
|
52 |
+ |
pSb.append( "\n " ).append( pToAppend ); |
|
53 |
+ |
} |
|
54 |
+ |
} |
|
55 |
+ |
|
|
56 |
+ |
public void clear() { |
|
57 |
+ |
// Local Group |
|
58 |
+ |
mPublishedEvents.clear(); |
|
59 |
+ |
mSubscribes.clear(); |
|
60 |
+ |
mUnsubscribes.clear(); |
|
61 |
+ |
// Remote Group |
|
62 |
+ |
mFromRemotePeerEvents.clear(); |
|
63 |
+ |
mAddRemotePeerInterests.clear(); |
|
64 |
+ |
mRemoveRemotePeerInterests.clear(); |
|
65 |
+ |
mFromRemoteAckPeerInterests.clear(); |
|
66 |
+ |
} |
|
67 |
+ |
|
|
68 |
+ |
public boolean isEmpty() { |
|
69 |
+ |
return // Local Group |
|
70 |
+ |
mPublishedEvents.isEmpty() && // |
|
71 |
+ |
mSubscribes.isEmpty() && // |
|
72 |
+ |
mUnsubscribes.isEmpty() && // |
|
73 |
+ |
// Remote Group |
|
74 |
+ |
mFromRemotePeerEvents.isEmpty() && // |
|
75 |
+ |
mAddRemotePeerInterests.isEmpty() && // |
|
76 |
+ |
mRemoveRemotePeerInterests.isEmpty() && // |
|
77 |
+ |
mFromRemoteAckPeerInterests.isEmpty(); |
|
78 |
+ |
} |
|
79 |
+ |
|
|
80 |
+ |
public void addSubscribes( EventSubscriptionStructure[] pSubscriptions ) { |
|
81 |
+ |
mSubscribes.add( pSubscriptions ); |
|
82 |
+ |
} |
|
83 |
+ |
|
|
84 |
+ |
public Iterator getSubscribes() { |
|
85 |
+ |
return mSubscribes.iterator(); |
|
86 |
+ |
} |
|
87 |
+ |
|
|
88 |
+ |
public void addUnsubscribes( EventSubscriptionStructure[] pSubscriptions ) { |
|
89 |
+ |
mUnsubscribes.add( pSubscriptions ); |
|
90 |
+ |
} |
|
91 |
+ |
|
|
92 |
+ |
public Iterator getUnsubscribes() { |
|
93 |
+ |
return mUnsubscribes.iterator(); |
|
94 |
+ |
} |
|
95 |
+ |
|
|
96 |
+ |
public void addPublishedEvent( EventPackage pPackage ) { |
|
97 |
+ |
mPublishedEvents.add( pPackage ); |
|
98 |
+ |
} |
|
99 |
+ |
|
|
100 |
+ |
public void addPublishedEvents( EventPackage[] pPackages ) { |
|
101 |
+ |
mPublishedEvents.add( pPackages ); |
|
102 |
+ |
} |
|
103 |
+ |
|
|
104 |
+ |
public Iterator getPublishedEvents() { |
|
105 |
+ |
return mPublishedEvents.iterator(); |
|
106 |
+ |
} |
|
107 |
+ |
|
|
108 |
+ |
public void addFromRemotePeerEvent( EventPackage pPackage ) { |
|
109 |
+ |
mFromRemotePeerEvents.add( pPackage ); |
|
110 |
+ |
} |
|
111 |
+ |
|
|
112 |
+ |
public void addFromRemotePeerEvents( EventPackage[] pPackages ) { |
|
113 |
+ |
mFromRemotePeerEvents.add( pPackages ); |
|
114 |
+ |
} |
|
115 |
+ |
|
|
116 |
+ |
public Iterator getFromRemotePeerEvents() { |
|
117 |
+ |
return mFromRemotePeerEvents.iterator(); |
|
118 |
+ |
} |
|
119 |
+ |
|
|
120 |
+ |
public void addRemotePeerInterests( String[] pInterests ) { |
|
121 |
+ |
mAddRemotePeerInterests.add( pInterests ); |
|
122 |
+ |
} |
|
123 |
+ |
|
|
124 |
+ |
public Set getAddRemotePeerInterests() { |
|
125 |
+ |
return mAddRemotePeerInterests.getAndClearSet(); |
|
126 |
+ |
} |
|
127 |
+ |
|
|
128 |
+ |
public void removeRemotePeerInterests( String[] pInterests ) { |
|
129 |
+ |
mRemoveRemotePeerInterests.add( pInterests ); |
|
130 |
+ |
} |
|
131 |
+ |
|
|
132 |
+ |
public Set getRemoveRemotePeerInterests() { |
|
133 |
+ |
return mRemoveRemotePeerInterests.getAndClearSet(); |
|
134 |
+ |
} |
|
135 |
+ |
|
|
136 |
+ |
public void addFromRemoteAckPeerInterests( String[] pInterests ) { |
|
137 |
+ |
mFromRemoteAckPeerInterests.add( pInterests ); |
|
138 |
+ |
} |
|
139 |
+ |
|
|
140 |
+ |
public Iterator getFromRemoteAckPeerInterests() { |
|
141 |
+ |
return mFromRemoteAckPeerInterests.iterator(); |
|
142 |
+ |
} |
|
143 |
+ |
|
|
144 |
+ |
public static class SubscriptionList implements LoggingCollection { |
|
145 |
+ |
private List mMembers = new ArrayList(); |
|
146 |
+ |
private Logger mLogger; |
|
147 |
+ |
private String mLogText; |
|
148 |
+ |
|
|
149 |
+ |
public SubscriptionList( Logger pLogger, String pLogText ) { |
|
150 |
+ |
mLogger = pLogger; |
|
151 |
+ |
mLogText = pLogText; |
|
152 |
+ |
} |
|
153 |
+ |
|
|
154 |
+ |
public void add( EventSubscriptionStructure[] pNewMembers ) { |
|
155 |
+ |
if ( pNewMembers != null ) { |
|
156 |
+ |
for ( int i = 0; i < pNewMembers.length; i++ ) { |
|
157 |
+ |
add( pNewMembers[i] ); |
|
158 |
+ |
} |
|
159 |
+ |
} |
|
160 |
+ |
} |
|
161 |
+ |
|
|
162 |
+ |
public void add( EventSubscriptionStructure pNewMember ) { |
|
163 |
+ |
if ( pNewMember != null ) { |
|
164 |
+ |
mLogger.trace.log( "(", mLogText, "):", pNewMember ); |
|
165 |
+ |
mMembers.add( pNewMember ); |
|
166 |
+ |
} |
|
167 |
+ |
} |
|
168 |
+ |
|
|
169 |
+ |
@Override |
|
170 |
+ |
public void clear() { |
|
171 |
+ |
mMembers.clear(); |
|
172 |
+ |
} |
|
173 |
+ |
|
|
174 |
+ |
@Override |
|
175 |
+ |
public boolean isEmpty() { |
|
176 |
+ |
return mMembers.isEmpty(); |
|
177 |
+ |
} |
|
178 |
+ |
|
|
179 |
+ |
@Override |
|
180 |
+ |
public Iterator iterator() { |
|
181 |
+ |
return isEmpty() ? Iterators.empty() : mMembers.iterator(); |
|
182 |
+ |
} |
|
183 |
+ |
|
|
184 |
+ |
public String toString() { |
|
185 |
+ |
return mLogText + ":" + mMembers; |
|
186 |
+ |
} |
|
187 |
+ |
} |
|
188 |
+ |
} |