xmlBlaster 2.2.0 API

org.xmlBlaster.protocol.http.appletproxy
Class PushHandler

java.lang.Object
  extended by org.xmlBlaster.protocol.http.appletproxy.PushHandler
All Implemented Interfaces:
I_Callback, I_Timeout

public class PushHandler
extends java.lang.Object
implements I_Callback, I_Timeout

This handles and hides the different http push modes when sending data back to the applet through method update().
Push mode works with keeping a permanent http connection

TODO: HTTP 1.1 specifies rfc2616 that the connection stays open as the default case. How must this code be changed?

See Java Servlet Programming from Jason Hunter

Author:
Marcel Ruff xmlBlaster@marcelruff.info

Field Summary
private  I_Callback callbackInterceptor
           
private  boolean closed
          Current http connection state
private  Global glob
           
(package private)  boolean isChunked
           
private static java.util.logging.Logger log
           
private  java.lang.String ME
           
private  long missingPongs
           
private  javax.servlet.ServletOutputStream outMulti
           
private  long pingCounter
           
private  long pingInterval
          Ping the applet every 10 seconds.
private  Timestamp pingTimeoutHandle
           
private  javax.servlet.http.HttpServletResponse res
           
private  java.lang.String sessionId
           
private  Timeout timeout
           
private  I_XmlBlasterAccess xmlBlasterAccess
           
 
Constructor Summary
PushHandler(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.lang.String sessionId, java.lang.String loginName, I_XmlBlasterAccess xmlBlasterAccess, Timeout timeout)
          Use the persistent HTTP callback connection.
 
Method Summary
 void cleanup()
          Shutdown applet connection and xmlBlaster connection.
 I_XmlBlasterAccess getXmlBlasterAccess()
           
 boolean isClosed()
           
 void ping(java.lang.String state)
          calls the ping method in the parentframe of the callback frame The data must be Javascript code
 void pong()
          This is the browser response for our previous ping.
private  void pushToApplet(byte[] chunk)
          Pushing a message to the applet.
 void setPingInterval(long pingInterval)
          Set or change the ping interval.
 void setProxyInterceptor(I_Callback interceptor)
          If you implement I_ProxyInterceptor and register it here, your update() implementation is called and may manipulate the received message from xmlBlaster before it is sent to the applet.
 void shutdownAppletConnection()
          Don't forget to call this method when you want to close the connection.
 void startPing()
           
 void stopPing()
           
 void timeout(java.lang.Object userData)
          You will be notified about the timeout through this method.
 java.lang.String update(java.lang.String sessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos)
          Pushes received message back to browser or applet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ME

private java.lang.String ME

glob

private Global glob

log

private static java.util.logging.Logger log

pingInterval

private long pingInterval
Ping the applet every 10 seconds.


timeout

private final Timeout timeout

pingTimeoutHandle

private Timestamp pingTimeoutHandle

pingCounter

private long pingCounter

missingPongs

private long missingPongs

xmlBlasterAccess

private I_XmlBlasterAccess xmlBlasterAccess

callbackInterceptor

private I_Callback callbackInterceptor

res

private javax.servlet.http.HttpServletResponse res

sessionId

private java.lang.String sessionId

closed

private boolean closed
Current http connection state


outMulti

private javax.servlet.ServletOutputStream outMulti

isChunked

boolean isChunked
Constructor Detail

PushHandler

public PushHandler(javax.servlet.http.HttpServletRequest req,
                   javax.servlet.http.HttpServletResponse res,
                   java.lang.String sessionId,
                   java.lang.String loginName,
                   I_XmlBlasterAccess xmlBlasterAccess,
                   Timeout timeout)
            throws javax.servlet.ServletException,
                   java.io.IOException
Use the persistent HTTP callback connection.

Parameters:
res - The response object
sessionId - The applet id
loginName - For loggin only
xmlBlasterAccess - Not yet logged in
Throws:
javax.servlet.ServletException
java.io.IOException
Method Detail

timeout

public void timeout(java.lang.Object userData)
Description copied from interface: I_Timeout
You will be notified about the timeout through this method.

Specified by:
timeout in interface I_Timeout
Parameters:
userData -
See Also:
I_Timeout

startPing

public void startPing()
               throws XmlBlasterException
Throws:
XmlBlasterException

stopPing

public void stopPing()
              throws XmlBlasterException
Throws:
XmlBlasterException

isClosed

public boolean isClosed()

setPingInterval

public void setPingInterval(long pingInterval)
                     throws XmlBlasterException
Set or change the ping interval.

Ping the applet to avoid that the web server or a internet proxy closes the http connection after a vendor specific timeout.
Note that the ping sends some bytes as well, a proxy may close the http connection if the amount of bytes per second falls below a certain level.
The applet responses with 'pong' which allows us to check if the applet is still here.

Parameters:
pingInterval - in milli seconds (defaults to 10000)
Throws:
XmlBlasterException

getXmlBlasterAccess

public I_XmlBlasterAccess getXmlBlasterAccess()

shutdownAppletConnection

public void shutdownAppletConnection()
Don't forget to call this method when you want to close the connection.


setProxyInterceptor

public void setProxyInterceptor(I_Callback interceptor)
If you implement I_ProxyInterceptor and register it here, your update() implementation is called and may manipulate the received message from xmlBlaster before it is sent to the applet.

Parameters:
interceptor - Your optional implementation

cleanup

public void cleanup()
Shutdown applet connection and xmlBlaster connection.


pushToApplet

private void pushToApplet(byte[] chunk)
                   throws java.io.IOException
Pushing a message to the applet.

Parameters:
chunk - The raw data, we encode it with base64, the applet must know how to handle it.
Throws:
java.io.IOException

update

public java.lang.String update(java.lang.String sessionId,
                               UpdateKey updateKey,
                               byte[] content,
                               UpdateQos updateQos)
Pushes received message back to browser or applet.

The callbacks are java-serialized Maps for key/qos etc.

 Format:  Serialized 
      "'update' sessionId QoS Key Content"
 and then Base64 encoded
 

Specified by:
update in interface I_Callback
Parameters:
sessionId - The session ID specified by the client which registered the callback. You can specify a cbSessionId during connection (with ConnectQos) and this is bounced back here so you can authenticate the message.
updateKey - The arrived key containing the topic name
content - The arrived message content. This is your payload.
See Also:
I_XmlBlasterAccess

ping

public void ping(java.lang.String state)
          throws XmlBlasterException
calls the ping method in the parentframe of the callback frame The data must be Javascript code

Parameters:
state - The string "refresh"
When login is done successfully, state="loginSucceeded" is sent one time
Throws:
XmlBlasterException

pong

public void pong()
This is the browser response for our previous ping.


xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.