nl.justobjects.pushlet.client
Class PushletClient

java.lang.Object
  extended by nl.justobjects.pushlet.client.PushletClient
All Implemented Interfaces:
Protocol

public class PushletClient
extends java.lang.Object
implements Protocol

Client API for Java HTTP client applets or apps.

Use this class within Java client applications or applets. Implement a PushletClientListener to receive callbacks for data-related Event objects pushed by the server.

This class may also be used as a base class and be extended for custom clients, hence the presence of many proteced methods.

Version:
$Id: PushletClient.java,v 1.19 2009/06/04 12:46:35 justb Exp $
Author:
Just van den Broecke - Just Objects ©
See Also:
PushletClientListener, PushletApplet, PushletPingApplication

Nested Class Summary
protected  class PushletClient.DataEventListener
          Internal (default) listener for the Pushlet data channel.
private static class PushletClient.HTTPAuthenticateProxy
          Authenticator
 
Field Summary
protected  PushletClient.DataEventListener dataEventListener
          Internal listener for data events pushed by server.
private  boolean debug
          Debug flag for verbose output.
private  java.lang.String id
          Id gotten on join ack
private  java.lang.String pushletURL
          Pushlet URL.
 
Fields inherited from interface nl.justobjects.pushlet.core.Protocol
DEFAULT_SERVLET_URI, E_ABORT, E_DATA, E_HEARTBEAT, E_HEARTBEAT_ACK, E_JOIN, E_JOIN_ACK, E_JOIN_LISTEN, E_JOIN_LISTEN_ACK, E_LEAVE, E_LEAVE_ACK, E_LISTEN, E_LISTEN_ACK, E_NACK, E_PUBLISH, E_PUBLISH_ACK, E_REFRESH, E_REFRESH_ACK, E_SUBSCRIBE, E_SUBSCRIBE_ACK, E_UNSUBSCRIBE, E_UNSUBSCRIBE_ACK, FORMAT_JAVASCRIPT, FORMAT_SERIALIZED_JAVA_OBJECT, FORMAT_XML, FORMAT_XML_STRICT, MODE_POLL, MODE_PULL, MODE_STREAM, P_EVENT, P_FORMAT, P_FROM, P_ID, P_MODE, P_REASON, P_SEQ, P_SUBJECT, P_SUBSCRIPTION_ID, P_SUBSCRIPTION_LABEL, P_TIME, P_TO, P_URL, P_WAIT, SUBJECT_META, SUBJECT_META_JOINS, SUBJECT_META_SUBS
 
Constructor Summary
PushletClient(java.lang.String aPushletURL)
          Constructor with full pushlet URL.
PushletClient(java.lang.String aHost, int aPort)
          Constructor with host and port using default URI.
 
Method Summary
protected  Event doControl(Event aControlEvent)
          Send control events to server and return response.
 void join()
          Join server, starts session.
 void joinListen(PushletClientListener aListener, java.lang.String aMode, java.lang.String aSubject)
          Immediate listener: joins/subscribes and listens in one action.
 void leave()
          Leave server, stops session.
 void listen(PushletClientListener aListener)
          Open data channel.
 void listen(PushletClientListener aListener, java.lang.String aMode)
          Open data channel in stream or push mode.
 void listen(PushletClientListener aListener, java.lang.String aMode, java.lang.String aSubject)
          Open data channel in stream or push mode with a subject.
protected  java.io.Reader openURL(java.lang.String aURL)
           
protected  void p(java.lang.String s)
          Util: print.
 void publish(java.lang.String aSubject, java.util.Map theAttributes)
          Publish an event through server.
 void setDebug(boolean b)
           
 void setProxyOptions(java.lang.String aProxyHost, java.lang.String aProxyPort, java.lang.String theNonProxyHosts, java.lang.String aUserName, java.lang.String aPassword, java.lang.String anNTLMDomain)
          Set proxy options and optional proxy authentication.
protected  void startDataEventListener(PushletClientListener aListener, java.lang.String aListenURL)
          Starts default DataEventListener and waits for its thread to start.
 void stopListen()
          Stop the listener.
 java.lang.String subscribe(java.lang.String aSubject)
          Subscribes, returning subscription id.
 java.lang.String subscribe(java.lang.String aSubject, java.lang.String aLabel)
          Subscribes, returning subscription id.
protected  void throwOnInvalidSession()
           
protected  void throwOnNack(Event anEvent)
           
 void unsubscribe()
          Unsubscribes from all subjects.
 void unsubscribe(java.lang.String aSubscriptionId)
          Unsubscribes with subscription id.
protected  void warn(java.lang.String s)
          Util: warn.
protected  void warn(java.lang.String s, java.lang.Throwable t)
          Util: warn with exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pushletURL

private java.lang.String pushletURL
Pushlet URL.


debug

private boolean debug
Debug flag for verbose output.


id

private java.lang.String id
Id gotten on join ack


dataEventListener

protected PushletClient.DataEventListener dataEventListener
Internal listener for data events pushed by server.

Constructor Detail

PushletClient

public PushletClient(java.lang.String aPushletURL)
Constructor with full pushlet URL.


PushletClient

public PushletClient(java.lang.String aHost,
                     int aPort)
Constructor with host and port using default URI.

Method Detail

setProxyOptions

public void setProxyOptions(java.lang.String aProxyHost,
                            java.lang.String aProxyPort,
                            java.lang.String theNonProxyHosts,
                            java.lang.String aUserName,
                            java.lang.String aPassword,
                            java.lang.String anNTLMDomain)
Set proxy options and optional proxy authentication.

Contributed by Dele Olajide See http://groups.yahoo.com/group/pushlet/message/634

Usage: PushletClient pushletClient = new PushletClient("http:://www.domain.com/pushlet"); pushletClient.setProxyOptions("proxy.bla.com", "8080", ....);

use pushletClient further as normal


join

public void join()
          throws PushletException
Join server, starts session.

Throws:
PushletException

leave

public void leave()
           throws PushletException
Leave server, stops session.

Throws:
PushletException

listen

public void listen(PushletClientListener aListener)
            throws PushletException
Open data channel.

Throws:
PushletException

listen

public void listen(PushletClientListener aListener,
                   java.lang.String aMode)
            throws PushletException
Open data channel in stream or push mode.

Throws:
PushletException

listen

public void listen(PushletClientListener aListener,
                   java.lang.String aMode,
                   java.lang.String aSubject)
            throws PushletException
Open data channel in stream or push mode with a subject.

Throws:
PushletException

joinListen

public void joinListen(PushletClientListener aListener,
                       java.lang.String aMode,
                       java.lang.String aSubject)
                throws PushletException
Immediate listener: joins/subscribes and listens in one action.

Throws:
PushletException

publish

public void publish(java.lang.String aSubject,
                    java.util.Map theAttributes)
             throws PushletException
Publish an event through server.

Throws:
PushletException

subscribe

public java.lang.String subscribe(java.lang.String aSubject,
                                  java.lang.String aLabel)
                           throws PushletException
Subscribes, returning subscription id.

Throws:
PushletException

subscribe

public java.lang.String subscribe(java.lang.String aSubject)
                           throws PushletException
Subscribes, returning subscription id.

Throws:
PushletException

unsubscribe

public void unsubscribe(java.lang.String aSubscriptionId)
                 throws PushletException
Unsubscribes with subscription id.

Throws:
PushletException

unsubscribe

public void unsubscribe()
                 throws PushletException
Unsubscribes from all subjects.

Throws:
PushletException

stopListen

public void stopListen()
                throws PushletException
Stop the listener.

Throws:
PushletException

setDebug

public void setDebug(boolean b)

startDataEventListener

protected void startDataEventListener(PushletClientListener aListener,
                                      java.lang.String aListenURL)
Starts default DataEventListener and waits for its thread to start.


throwOnNack

protected void throwOnNack(Event anEvent)
                    throws PushletException
Throws:
PushletException

throwOnInvalidSession

protected void throwOnInvalidSession()
                              throws PushletException
Throws:
PushletException

openURL

protected java.io.Reader openURL(java.lang.String aURL)
                          throws PushletException
Throws:
PushletException

doControl

protected Event doControl(Event aControlEvent)
                   throws PushletException
Send control events to server and return response.

Throws:
PushletException

p

protected void p(java.lang.String s)
Util: print.


warn

protected void warn(java.lang.String s)
Util: warn.


warn

protected void warn(java.lang.String s,
                    java.lang.Throwable t)
Util: warn with exception.



Copyright 2000-2003 - Just Objects B.V.