Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.drools.guvnor.client.rpc;
 
 
 import java.util.List;
 
This manages "subscriptions" for when messages are pushed from the server.
 
 public class PushClient {
 
 
     private static final PushClient INSTANCE = new PushClient();
 
     public static PushClient instance() {
         return ;
     }
     
     private PushClient() {
     }
 
     private boolean connected = false;
 
     public void subscribe(ServerPushNotification pushed) {
         if (!connect();
         .add(pushed);
     }
 
     private void connect() {
          = true;
         
         ..println("Connecting" + System.currentTimeMillis());
         Timer timer = new Timer() {
 
             public void run() {
                 RepositoryServiceAsync repositoryService = GWT.create(RepositoryService.class);
                 repositoryService.subscribe(new AsyncCallback<List<PushResponse>>() {
                     public void onFailure(Throwable caught) {
                         ..println("FAIL" + System.currentTimeMillis());
                     }
 
                     public void onSuccess(List<PushResponseresult) {
                         //System.err.println("Got response !" + System.currentTimeMillis());
                         processResult(result);
                     }
                 });
             }
 
         };
 
         timer.scheduleRepeating( 60000 );
 /*        
         RepositoryServiceAsync repositoryService = GWT.create(RepositoryService.class);
         repositoryService.subscribe(new AsyncCallback<List<PushResponse>>() {
             public void onFailure(Throwable caught) {
                 System.err.println("FAIL" + System.currentTimeMillis());
                 
                 connect();
             }
 
             public void onSuccess(List<PushResponse> result) {
                 System.err.println("Got response !" + System.currentTimeMillis());
                 processResult(result);
                 connect();
             }
         });*/
 
     }
 
     private void processResult(List<PushResponseresult) {
         if (result == null) {
             ..println("NULL result :(");
             return;
         }
         for (PushResponse msgresult) {
             ..println("Processing pushed message:" + msg.messageType + "," + msg.message);
             for (ServerPushNotification pn : ) {
                ..println("performing callback...");
                pn.messageReceived(msg);
            }
        }
    }
    public void unsubscribe(ServerPushNotification pushed) {
        .remove(pushed);
    }
New to GrepCode? Check out our FAQ X