Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/Java/GWT/OldClient/src/org/litesoft/GWT/eventbus/client/rpc/ClientSideRemotePeerService.java

Diff revisions: vs.
  @@ -8,11 +8,9 @@
8 8 import org.litesoft.logger.nonpublic.*;
9 9
10 10 import com.google.gwt.user.client.*;
11 - import com.google.gwt.user.client.Timer;
12 11 import com.google.gwt.user.client.rpc.*;
13 12
14 - public class ClientSideRemotePeerService implements RemotePeerService
15 - {
13 + public class ClientSideRemotePeerService implements RemotePeerService {
16 14 private static final String COMMUNICATION_FAILURE = "TheServerCommunication";
17 15
18 16 private static PeerSupportingEventBus sClientEventBus;
  @@ -23,8 +21,7 @@
23 21
24 22 public ClientSideRemotePeerService( PeerSupportingEventBus pClientEventBus, //
25 23 ChannelServiceAsync pChannelServiceAsync, //
26 - int pPollSecs )
27 - {
24 + int pPollSecs ) {
28 25 sClientEventBus = pClientEventBus;
29 26 sClientIdNumber = pClientEventBus.getClientIdNumber();
30 27 sChannelServiceAsync = pChannelServiceAsync;
  @@ -32,45 +29,38 @@
32 29 sPollTimer = (sPollMillisecs <= 0) ? NoPollTimer.INSTANCE : new RealPollTimer();
33 30 }
34 31
35 - public String toString()
36 - {
32 + public String toString() {
37 33 return "ClientSideRemotePeerService";
38 34 }
39 35
40 - public boolean forwardTo( ChannelServicePackage pFromPeer )
41 - {
36 + public boolean forwardTo( ChannelServicePackage pFromPeer ) {
42 37 return (pFromPeer == null) || pFromPeer.isEmpty() || //
43 38 sendEm( ForwardToAsyncCallback.INSTANCE, pFromPeer );
44 39 }
45 40
46 - public void stopUnrequestedMessages()
47 - {
41 + public void stopUnrequestedMessages() {
48 42 sPollTimer.cancel();
49 43 }
50 44
51 - public RemotePeerService dispose()
52 - {
45 + public RemotePeerService dispose() {
53 46 return RemotePeerService.Null.INSTANCE;
54 47 }
55 48
56 49 private static int sMessageSequenceNumber = 0;
57 50
58 51 private static boolean sendEm( AsyncCallback pAsyncCallback,
59 - ChannelServicePackage pChannelServicePackage )
60 - {
52 + ChannelServicePackage pChannelServicePackage ) {
61 53 boolean sent = false;
62 54 sPollTimer.cancel();
63 55 sMessageSequenceNumber++;
64 - try
65 - {
56 + try {
66 57 trace( ">", pAsyncCallback, sMessageSequenceNumber );
67 58 sChannelServiceAsync.propagate( sClientIdNumber, sMessageSequenceNumber, //
68 59 sPollMillisecs, pChannelServicePackage, //
69 60 pAsyncCallback );
70 61 sent = true;
71 62 }
72 - catch ( RuntimeException e )
73 - {
63 + catch ( RuntimeException e ) {
74 64 sClientEventBus.handleUnexpectedProblem( COMMUNICATION_FAILURE, //
75 65 new Problem( e, "SendingToServer" ) );
76 66 }
  @@ -78,67 +68,51 @@
78 68 return sent;
79 69 }
80 70
81 - private interface PollTimer
82 - {
71 + private interface PollTimer {
83 72 public void cancel();
84 73
85 74 public void schedule();
86 75 }
87 76
88 - private static class RealPollTimer extends Timer implements PollTimer
89 - {
90 - public void run()
91 - {
92 - if ( !AbstractClientMainAppEntryPoint.sWindowClosing )
93 - {
77 + private static class RealPollTimer extends Timer implements PollTimer {
78 + public void run() {
79 + if ( !AbstractClientMainAppEntryPoint.sWindowClosing ) {
94 80 sendEm( PollAsyncCallback.INSTANCE, null );
95 81 }
96 82 }
97 83
98 - public void schedule()
99 - {
84 + public void schedule() {
100 85 schedule( sPollMillisecs );
101 86 }
102 87 }
103 88
104 - private static class NoPollTimer implements PollTimer
105 - {
89 + private static class NoPollTimer implements PollTimer {
106 90 public static final PollTimer INSTANCE = new NoPollTimer();
107 91
108 - public void cancel()
109 - {
92 + public void cancel() {
110 93 }
111 94
112 - public void schedule()
113 - {
95 + public void schedule() {
114 96 }
115 97 }
116 98
117 - private static class AbstractAsyncCallback implements AsyncCallback
118 - {
99 + private static class AbstractAsyncCallback implements AsyncCallback {
119 100 private String mTypeString;
120 101
121 - protected AbstractAsyncCallback( String pTypeString )
122 - {
102 + protected AbstractAsyncCallback( String pTypeString ) {
123 103 mTypeString = pTypeString;
124 104 }
125 105
126 - public void onSuccess( Object pObject )
127 - {
128 - if ( !AbstractClientMainAppEntryPoint.sWindowClosing )
129 - {
106 + public void onSuccess( Object pObject ) {
107 + if ( !AbstractClientMainAppEntryPoint.sWindowClosing ) {
130 108 ChannelServiceResult result = (ChannelServiceResult) pObject;
131 109 trace( "<", this, result.getMessageSequenceNumber() );
132 - if ( result.isForceClose() || result.isServerLost() )
133 - {
110 + if ( result.isForceClose() || result.isServerLost() ) {
134 111 sPollTimer.cancel();
135 112 sPollTimer = NoPollTimer.INSTANCE;
136 - if ( result.isForceClose() )
137 - {
113 + if ( result.isForceClose() ) {
138 114 UtilsGwt.closeWindowNoConfirm( 5 );
139 - }
140 - else
141 - {
115 + } else {
142 116 sClientEventBus.problemFromRemotePeerService(
143 117 new NoServerEventBusEventPackage( "ChannelClient" ) );
144 118 }
  @@ -148,61 +122,50 @@
148 122 }
149 123 }
150 124
151 - private static class DeferredServerMessageHandler implements Command
152 - {
125 + private static class DeferredServerMessageHandler implements Command {
153 126 private AsyncCallback mAsyncCallback;
154 127 private ChannelServiceResult mResult;
155 128
156 - public DeferredServerMessageHandler( AsyncCallback pAsyncCallback, ChannelServiceResult pResult )
157 - {
129 + public DeferredServerMessageHandler( AsyncCallback pAsyncCallback, ChannelServiceResult pResult ) {
158 130 mAsyncCallback = pAsyncCallback;
159 131 mResult = pResult;
160 132 }
161 133
162 - public void execute()
163 - {
134 + public void execute() {
164 135 trace( "#", mAsyncCallback, mResult.getMessageSequenceNumber() );
165 136 ChannelServicePackage zPackage = mResult.getPackage();
166 - if ( !sClientEventBus.propagateFromRemotePeerService( zPackage ) )
167 - {
137 + if ( !sClientEventBus.propagateFromRemotePeerService( zPackage ) ) {
168 138 sClientEventBus = PeerSupportingEventBus.Null.INSTANCE;
169 139 }
170 140 trace( "$", mAsyncCallback, mResult.getMessageSequenceNumber() );
171 141 }
172 142 }
173 143
174 - public void onFailure( Throwable pThrowable )
175 - {
176 - if ( !AbstractClientMainAppEntryPoint.sWindowClosing )
177 - {
144 + public void onFailure( Throwable pThrowable ) {
145 + if ( !AbstractClientMainAppEntryPoint.sWindowClosing ) {
178 146 sClientEventBus.handleUnexpectedProblem( COMMUNICATION_FAILURE, new Problem( pThrowable,
179 147 "Failed to contact the server",
180 148 toString() ) );
181 149 }
182 150 }
183 151
184 - public String toString()
185 - {
152 + public String toString() {
186 153 return mTypeString;
187 154 }
188 155 }
189 156
190 - private static class PollAsyncCallback extends AbstractAsyncCallback
191 - {
157 + private static class PollAsyncCallback extends AbstractAsyncCallback {
192 158 public static final AsyncCallback INSTANCE = new PollAsyncCallback();
193 159
194 - private PollAsyncCallback()
195 - {
160 + private PollAsyncCallback() {
196 161 super( "POLL" );
197 162 }
198 163 }
199 164
200 - private static class ForwardToAsyncCallback extends AbstractAsyncCallback
201 - {
165 + private static class ForwardToAsyncCallback extends AbstractAsyncCallback {
202 166 public static final AsyncCallback INSTANCE = new ForwardToAsyncCallback();
203 167
204 - private ForwardToAsyncCallback()
205 - {
168 + private ForwardToAsyncCallback() {
206 169 super( "FRWD" );
207 170 }
208 171 }
  @@ -210,11 +173,9 @@
210 173 /**
211 174 * @noinspection UnusedDeclaration
212 175 */
213 - private static void trace( String pDirection, AsyncCallback pAsyncCallback, int pMessageSequenceNumber )
214 - {
176 + private static void trace( String pDirection, AsyncCallback pAsyncCallback, int pMessageSequenceNumber ) {
215 177 AbstractLogger zLogger = sClientEventBus.getLogger().trace();
216 - if ( zLogger.isEnabled() )
217 - {
178 + if ( zLogger.isEnabled() ) {
218 179 zLogger.log( "CC-" + pAsyncCallback + " " + +sClientIdNumber + "|" + pMessageSequenceNumber +
219 180 " " + pDirection + " " + SimpleTimestamp.now() );
220 181 }