Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //========================================================================
  // Copyright 2008 Mort Bay Consulting Pty. Ltd.
  // ------------------------------------------------------------------------
  // 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.cometd.client;
 
 import java.util.Map;

Advice

Implementation of advice field from Bayeux message.

 
 public class Advice {
     //reconnect: retry, handshake, none
     public static final int __RECONNECT_RETRY = 0;
     public static final int __RECONNECT_HANDSHAKE = 1;
     public static final int __RECONNECT_NONE = 2;
     private Integer _reconnect;
 
     //interval: ms
     private Long _interval;
 
     //multiple-clients: boolean
     private Boolean _multipleClients;
 
     //hosts: list
     private String[] _hosts;
 
     private Map _adviceField;
 
 
     public Advice(Map adviceField) {
          = adviceField;
     }

    
A client MAY attempt to reconnect with a /meta/connect after the interval (as defined by "interval" advice or client-default backoff), and with the same credentials.

Returns:
 
     public boolean isReconnectRetry() {
         if ( == null &&  != null)
              = parseReconnect((String.get("reconnect"));
 
         return  != null && .intValue() == ;
     }

    
The server has terminated any prior connection status and the client MUST reconnect with a /meta/handshake. A client MUST NOT automatically retry if handshake advice has been received.

Returns:
 
     public boolean isReconnectHandshake() {
         if ( == null &&  != null)
              = parseReconnect((String.get("reconnect"));
 
         return  != null && .intValue() == ;
     }

    
Hard failure for the connect attempt. Do not attempt to reconnect at all. A client MUST respect reconnect advice of none and MUST NOT automatically retry or handshake.

Returns:
 
     public boolean isReconnectNone() {
         if ( == null &&  != null)
              = parseReconnect((String.get("reconnect"));
 
         return  != null && .intValue() == ;
     }
 
     public long getInterval() {
         if ( == null &&  != null)
              = (Long.get("interval");
 
         return ( == null ? 0 : .longValue());
     }
 
     public boolean isMultipleClients() {
         if ( == null &&  != null)
              = (Boolean.get("multiple-clients");
 
        return ( == null ? false : .booleanValue());
    }
    public String[] getHosts() {
        if ( == null &&  != null) {
            Object[] hosts = (Object[]) .get("hosts");
            if (hosts != null) {
                 = new String[hosts.length];
                System.arraycopy(hosts, 0, , 0, hosts.length);
            }
        }
        return ;
    }
    private Integer parseReconnect(String reconnect) {
        if (reconnect != null) {
            reconnect = reconnect.trim();
            if (reconnect.equalsIgnoreCase("retry"))
                return new Integer();
            else if (reconnect.equalsIgnoreCase("handshake"))
                return new Integer();
            else if (reconnect.equalsIgnoreCase("none"))
                return new Integer();
        }
        return null;
    }
New to GrepCode? Check out our FAQ X