prometheus
Class PrometheusCallback

java.lang.Object
  |
  +--prometheus.PrometheusCallback

public class PrometheusCallback
extends java.lang.Object

Prometheus token callback.

Changes:

alexis.grandemange@pagebox.net

Copyright (c) 2003-2004 Alexis Grandemange

This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public License
 as published by the Free Software Foundation; version 2.1 of the
 License.
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU Lesser General Public License for more details.
 A copy of the GNU Lesser General Public License lesser.txt should be
 included in the distribution.

Version:
0, 0, 3
Author:
Alexis Grandemange

Field Summary
(package private)  ServletContext ctx
          Servlet context unique in the Web application
 java.util.HashMap foreignUsers
          User map. Key: instance URL Value: HashMap whose key is a user name and value a UserInfo object
(package private)  PageBoxAPI inst
          PageBox API instance
(package private)  boolean isRegistered
          True when inserted on the ring
(package private)  PageBoxLib.LogIF log
          Logging object
 java.util.HashMap messages
          Map of messages sent outside. Key: destination or all when all destinations Value: Message object
(package private)  java.util.HashMap received
          Map of received messages. Key: user name Value: TreeMap whose key is the origin PageBox and value is a TreeMap whose key is a timestamp and value is a message string
private  java.text.SimpleDateFormat sdf
          SimpleDateFormat used to build log entries
(package private)  TokenSendIF sender
          Token sender
(package private)  java.lang.String subUrl
          URL of the DeployIF web service of the controlling PageBox
 java.util.HashMap users
          User map. Key: user name Value: UserInfo object
(package private)  java.lang.String workDir
          Prometheus directory
 
Constructor Summary
(package private) PrometheusCallback(ServletContext ctx, java.lang.String workDir)
          Constructor.
 
Method Summary
private  void addLocalMessage(java.lang.String u, java.lang.String date, java.lang.String from, java.lang.String message)
          Add a message to a local user.
(package private)  boolean addUser(LoginBean lb)
          Add a user to the user map.
 java.io.Serializable call(java.lang.String from, java.lang.String type, int corrid, java.io.Serializable data)
          Method called when a message that targets this (target instance, archive) is received.
(package private)  void end()
          Remove the application from the ring.
(package private)  java.util.TreeMap getUserMessages(java.lang.String user)
          Get messages for the specified user.
private  boolean matchingFilter(java.lang.String filter, java.lang.String user)
          Parses the filter string and compare to the user definition.
 void poll()
          Method called when a frame is received by the PageBox.
(package private)  void removeUser(java.lang.String user)
          Remove a user from the user map.
 void response(java.lang.String type, int corrid, java.util.Map codes)
          Method called when a message comes back to its sender.
(package private)  void send(java.lang.String from, java.lang.String message)
          Send a message to all users.
(package private)  void send(java.lang.String user, java.lang.String from, java.lang.String message)
          Send a message to the specified user.
(package private)  void send(java.lang.String pagebox, java.lang.String filter, java.lang.String from, java.lang.String message)
          Send a message to users matching pagebox URL and filter.
(package private)  void sendFiltered(java.lang.String filter, java.lang.String from, java.lang.String message)
          Send a message to all users matching the filter.
(package private)  void sendTo(java.lang.String pagebox, java.lang.String from, java.lang.String message)
          Send a message to all users on the specified PageBox.
 void setSender(TokenSendIF tsi)
          Method called when a callback is registered
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

workDir

java.lang.String workDir
Prometheus directory


ctx

ServletContext ctx
Servlet context unique in the Web application


inst

PageBoxAPI inst
PageBox API instance


log

PageBoxLib.LogIF log
Logging object


sender

TokenSendIF sender
Token sender


users

public java.util.HashMap users
User map.


foreignUsers

public java.util.HashMap foreignUsers
User map.


messages

public java.util.HashMap messages
Map of messages sent outside.


received

java.util.HashMap received
Map of received messages.


sdf

private final java.text.SimpleDateFormat sdf
SimpleDateFormat used to build log entries


subUrl

java.lang.String subUrl
URL of the DeployIF web service of the controlling PageBox


isRegistered

boolean isRegistered
True when inserted on the ring

Constructor Detail

PrometheusCallback

PrometheusCallback(ServletContext ctx,
                   java.lang.String workDir)
Constructor.

Parameters:
ctx - servlet context unique in the Web application
workDir - Prometheus directory
Method Detail

addUser

final boolean addUser(LoginBean lb)
Add a user to the user map.

Parameters:
lb - user info

removeUser

final void removeUser(java.lang.String user)
Remove a user from the user map.

Parameters:
user - user name

end

final void end()
Remove the application from the ring. Called by LoginCtrl and PrometheusCtrl.


getUserMessages

java.util.TreeMap getUserMessages(java.lang.String user)
Get messages for the specified user.

Parameters:
user - user name
Returns:
TreeMap whose key is the origin instance and value is a TreeMap whose key is a timestamp and value is the message string

matchingFilter

private boolean matchingFilter(java.lang.String filter,
                               java.lang.String user)
Parses the filter string and compare to the user definition. Filter syntax: [loc/location] [sub/aoi]*

Parameters:
filter - filter string
user - name

send

void send(java.lang.String from,
          java.lang.String message)
Send a message to all users.

Parameters:
message - message to send
from - user who issued the message

addLocalMessage

private void addLocalMessage(java.lang.String u,
                             java.lang.String date,
                             java.lang.String from,
                             java.lang.String message)
Add a message to a local user.

Parameters:
u - user
date - time when the message was issued
from - user who issued the message
message - message to send

send

void send(java.lang.String user,
          java.lang.String from,
          java.lang.String message)
Send a message to the specified user.

Parameters:
user - qualified user name
from - user who issued the message
message - message to send

send

void send(java.lang.String pagebox,
          java.lang.String filter,
          java.lang.String from,
          java.lang.String message)
Send a message to users matching pagebox URL and filter.

Parameters:
pagebox - PageBox URL
filter - filter to apply
from - user who issued the message
message - message to send

sendTo

void sendTo(java.lang.String pagebox,
            java.lang.String from,
            java.lang.String message)
Send a message to all users on the specified PageBox.

Parameters:
pagebox - PageBox URL
from - user who issued the message
message - message to send

sendFiltered

void sendFiltered(java.lang.String filter,
                  java.lang.String from,
                  java.lang.String message)
Send a message to all users matching the filter.

Parameters:
filter - filter to apply
from - user who issued the message
message - message to send

setSender

public void setSender(TokenSendIF tsi)
Method called when a callback is registered

Parameters:
tsi - object to use to send messages
See Also:
PageBoxLib.TokenCallbackIF#setSender(TokenSendIF)

call

public java.io.Serializable call(java.lang.String from,
                                 java.lang.String type,
                                 int corrid,
                                 java.io.Serializable data)
Method called when a message that targets this (target instance, archive) is received.

Parameters:
from - issuer URL
type - request type
corrid - correlation ID
data - TokenMsg data
Returns:
return code
See Also:
PageBoxLib.TokenCallbackIF#call(String, int, Serializable)

poll

public void poll()
Method called when a frame is received by the PageBox. Must call getMessages. Used to send new messages.


response

public void response(java.lang.String type,
                     int corrid,
                     java.util.Map codes)
Method called when a message comes back to its sender.

Parameters:
type - request type
corrid - correlation ID
codes - map whose key is the issuer URL and value is a Serializable object (response returned by the call method of the issuer TokenCallbackIF)
See Also:
PageBoxLib.TokenCallbackIF#response(String, int, Map)