예제 #1
0
 public String getUrl(int connectionCount) {
   String url = client.getUrl();
   if (client.getSerializer() != null && client.getSerializer().getMode() == SerialMode.DE_RPC) {
     url +=
         (url.contains("?") ? "&" : "?")
             + Constants.MODULE_BASE_PARAMETER
             + '='
             + GWT.getModuleBaseURL()
             + '&'
             + Constants.STRONG_NAME_PARAMETER
             + '='
             + GWT.getPermutationStrongName();
   }
   String className = getClass().getName();
   className = className.substring(className.lastIndexOf('.') + 1);
   String transport = className.substring(0, className.indexOf("CometTransport"));
   return url
       + (url.contains("?") ? "&" : "?")
       + "t="
       + Integer.toString(
               (int) (Duration.currentTimeMillis() % Integer.MAX_VALUE), Character.MAX_RADIX)
           .toUpperCase()
       + "&c="
       + connectionCount
       + "&tr="
       + transport;
 }
  protected void onReceiving(int statusCode, String responseText, boolean connected) {
    if (statusCode != Response.SC_OK) {
      if (!connected) {
        expectingDisconnection = true;
        listener.onError(new StatusCodeException(statusCode, responseText), connected);
      }
    } else {
      int index = responseText.lastIndexOf(SEPARATOR);
      if (index > read) {
        List<Serializable> messages = new ArrayList<Serializable>();
        JsArrayString data = AtmosphereClient.split(responseText.substring(read, index), SEPARATOR);
        int length = data.length();
        for (int i = 0; i < length; i++) {
          if (aborted) {
            return;
          }
          parse(data.get(i), messages);
        }
        read = index + 1;
        if (!messages.isEmpty()) {
          listener.onMessage(messages);
        }
      }

      if (!connected) {
        if (expectingDisconnection) {
          listener.onDisconnected();
        } else {
          listener.onError(new AtmosphereClientException("Unexpected disconnection"), false);
        }
      }
    }
  }
예제 #3
0
  public void initialize() {

    MyCometListener cometListener = new MyCometListener();

    AtmosphereGWTSerializer serializer = GWT.create(EventSerializer.class);
    // set a small length parameter to force refreshes
    // normally you should remove the length parameter
    client = new AtmosphereClient(GWT.getModuleBaseURL() + "gwtComet", serializer, cometListener);
    client.start();
  }
예제 #4
0
 protected Serializable parse(String message) throws SerializationException {
   if (message == null || message.isEmpty()) {
     return null;
   }
   AtmosphereGWTSerializer serializer = client.getSerializer();
   if (serializer == null) {
     throw new SerializationException(
         "Can not deserialize message with no serializer: " + message);
   } else {
     return serializer.parse(message);
   }
 }