fix line endings in Paparazzi On the Web files

This commit is contained in:
Felix Ruess
2010-12-10 15:53:33 +01:00
parent a158af41cd
commit 9d0ea64388
94 changed files with 25242 additions and 25242 deletions
@@ -1,44 +1,44 @@
body body
{ {
background-color: #CCFFCC; background-color: #CCFFCC;
margin: 0%; margin: 0%;
padding: 0%; padding: 0%;
outline: 0%; outline: 0%;
height: 100%; height: 100%;
overflow:hidden; overflow:hidden;
max-width:2048px; max-width:2048px;
font-size : 11; font-size : 11;
} }
select{ select{
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 11px; font-size: 11px;
vertical-align: middle; vertical-align: middle;
background-color: #F5F5DC; background-color: #F5F5DC;
} }
input { input {
background-color:#F5F5DC; background-color:#F5F5DC;
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 10px; font-size: 10px;
} }
label { label {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 11px; font-size: 11px;
} }
#welcome #welcome
{ {
position:absolute; position:absolute;
top:0; top:0;
left:0; left:0;
height:3%; height:3%;
width: 100%; width: 100%;
background-color: #EEEEEE; background-color: #EEEEEE;
text-align: center; text-align: center;
font-weight:bold; font-weight:bold;
font-size : 12; font-size : 12;
} }
#usr #usr
{ {
position:absolute; position:absolute;
@@ -46,175 +46,175 @@ label {
right:6%; right:6%;
height:3%; height:3%;
width:25%; width:25%;
background-color: #EEEEEE; background-color: #EEEEEE;
text-align: right; text-align: right;
white-space:nowrap; white-space:nowrap;
} }
#page #page
{ {
position:absolute; position:absolute;
top:3%; top:3%;
left:0; left:0;
height:97%; height:97%;
width: 100%; width: 100%;
} }
#choicePanel{ #choicePanel{
position:absolute; position:absolute;
top:0%; top:0%;
left:0%; left:0%;
height: 13%; height: 13%;
width : 15%; width : 15%;
background-color: #EEEEEE; background-color: #EEEEEE;
border: 1px solid black; border: 1px solid black;
} }
#aircraftSelector #aircraftSelector
{ {
text-align: center; text-align: center;
background-color: #EEEEEE; background-color: #EEEEEE;
} }
#trackdiv #trackdiv
{ {
text-align: center; text-align: center;
background-color: #EEEEEE; background-color: #EEEEEE;
-moz-border-radius: 7px 7px 7px 7px; -moz-border-radius: 7px 7px 7px 7px;
-webkit-border-radius: 7px 7px 7px 7px; -webkit-border-radius: 7px 7px 7px 7px;
border-radius: 7px 7px 7px 7px; border-radius: 7px 7px 7px 7px;
-webkit-border-top-left-radius: 7px; /* pour Chrome */ -webkit-border-top-left-radius: 7px; /* pour Chrome */
-webkit-border-top-right-radius: 7px; /* pour Chrome */ -webkit-border-top-right-radius: 7px; /* pour Chrome */
-webkit-border-bottom-left-radius: 7px; /* pour Chrome */ -webkit-border-bottom-left-radius: 7px; /* pour Chrome */
-webkit-border-bottom-right-radius: 7px; /* pour Chrome */ -webkit-border-bottom-right-radius: 7px; /* pour Chrome */
width: 140px; width: 140px;
color: white; color: white;
vertical-align:middle; vertical-align:middle;
} }
#active_block #active_block
{ {
font-size:11; font-size:11;
text-align: center; text-align: center;
} }
#FlightPlan #FlightPlan
{ {
overflow:auto; overflow:auto;
position:absolute; position:absolute;
top:0%; top:0%;
left:15%; left:15%;
height: 40%; height: 40%;
width : 14.9%; width : 14.9%;
background-color: #EEEEEE; background-color: #EEEEEE;
border: 1px solid black; border: 1px solid black;
} }
#FlightParams #FlightParams
{ {
position:absolute; position:absolute;
top:13%; top:13%;
left :0% left :0%
text-align: center; text-align: center;
height: 27%; height: 27%;
width : 14.9%; width : 14.9%;
border: 1px solid black; border: 1px solid black;
background-color: #EEEEEE; background-color: #EEEEEE;
} }
#map_canvas #map_canvas
{ {
position:absolute; position:absolute;
top:0; top:0;
left:30%; left:30%;
width:70%; width:70%;
height: 95%; height: 95%;
border:1px solid black; border:1px solid black;
} }
#Settings #Settings
{ {
overflow:auto; overflow:auto;
position:absolute; position:absolute;
left:0%; left:0%;
top:40%; top:40%;
text-align: left; text-align: left;
height: 55%; height: 55%;
width: 29.9%; width: 29.9%;
background-color: #EEEEEE; background-color: #EEEEEE;
border: 1px solid black; border: 1px solid black;
} }
#page_setting { #page_setting {
} }
#setting { #setting {
width: 400px; width: 400px;
height: 250px; height: 250px;
padding: 0.5em; padding: 0.5em;
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 8; font-size: 8;
} }
#param #param
{ {
overflow:auto; overflow:auto;
} }
#NewsDiv #NewsDiv
{ {
position:absolute; position:absolute;
overflow:auto; overflow:auto;
left:0%; left:0%;
top:95%; top:95%;
height: 5%; height: 5%;
width: 100%; width: 100%;
text-align: left; text-align: left;
vertical-align:top; vertical-align:top;
background-color: #EEEEEE; background-color: #EEEEEE;
border: 1px solid black; border: 1px solid black;
} }
#info #info
{ {
text-align: left; text-align: left;
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 11px; font-size: 11px;
} }
#Debug #Debug
{ {
overflow:auto; overflow:auto;
position:absolute; position:absolute;
left:65%; left:65%;
top:50%; top:50%;
text-align: center; text-align: center;
height: 50%; height: 50%;
width: 35%; width: 35%;
background-color: #EEEEEE; background-color: #EEEEEE;
border: 1px solid black; border: 1px solid black;
padding-top:20px; padding-top:20px;
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 11px; font-size: 11px;
} }
#title{ #title{
font-weight:bold; font-weight:bold;
font-size:18; font-size:18;
text-align:center; text-align:center;
} }
table.param { table.param {
border:3px solid #6495ed; border:3px solid #6495ed;
border-collapse:collapse; border-collapse:collapse;
width:90%; width:90%;
margin:auto; margin:auto;
} }
td.param { td.param {
font-family:sans-serif; font-family:sans-serif;
font-size:11px; font-size:11px;
border:1px solid #6495ed; border:1px solid #6495ed;
padding:5px; padding:5px;
text-align:left; text-align:left;
} }
@@ -1,12 +1,12 @@
body body
{ {
width: 90%; width: 90%;
margin-top: 5px; margin-top: 5px;
margin-bottom: 5px; margin-bottom: 5px;
margin-left:5%; margin-left:5%;
margin-reight:5%; margin-reight:5%;
background-color: #CCFFCC; background-color: #CCFFCC;
text-align:justify; text-align:justify;
} }
h3,h2 h3,h2
@@ -1,12 +1,12 @@
body body
{ {
background-color: #CCFFCC; background-color: #CCFFCC;
margin-top: 2%; margin-top: 2%;
padding: 0%; padding: 0%;
outline: 0%; outline: 0%;
height: 100%; height: 100%;
overflow:hidden; overflow:hidden;
max-width:2048px; max-width:2048px;
text-align:center; text-align:center;
font-size:24px; font-size:24px;
} }
@@ -1,30 +1,30 @@
body body
{ {
width: 960px; width: 960px;
margin-top: 100px; margin-top: 100px;
margin-bottom: 5px; margin-bottom: 5px;
background-image: url("Icons/logo.png"); background-image: url("Icons/logo.png");
background-repeat:no-repeat; background-repeat:no-repeat;
background-color: #CCFFCC; background-color: #CCFFCC;
} }
#signIn #signIn
{
margin: auto;
width: 300px;
height: 140px;
border: 1px solid black;
}
#log
{
margin-left: 30px;
}
a
{ {
position:absolute; margin: auto;
width: 300px;
height: 140px;
border: 1px solid black;
}
#log
{
margin-left: 30px;
}
a
{
position:absolute;
right:1%; right:1%;
top:80%; top:80%;
} }
@@ -1,87 +1,87 @@
body body
{ {
background-color: #CCFFCC; background-color: #CCFFCC;
margin: 0%; margin: 0%;
padding: 0%; padding: 0%;
outline: 0%; outline: 0%;
height: 95%; height: 95%;
} }
#page #page
{ {
width: 100%; width: 100%;
height: 95%; height: 95%;
} }
#logo #logo
{ {
width: 960px; width: 960px;
height: 100px; height: 100px;
background-image: url("banniere.jpg"); background-image: url("banniere.jpg");
background-repeat: repeat-x; background-repeat: repeat-x;
margin-bottom: 10px; margin-bottom: 10px;
} }
#leftmenu #leftmenu
{ {
/* float: left; /* Le menu flottera à gauche */ /* float: left; /* Le menu flottera à gauche */
/* width: 120px; *//* Très important : donner une taille au menu */ /* width: 120px; *//* Très important : donner une taille au menu */
} }
#welcome #welcome
{ {
text-align: center; text-align: center;
background-color: #EEEEEE; background-color: #EEEEEE;
border: 2px solid black; border: 2px solid black;
margin-bottom: 10px; /* Pour éviter que les éléments du menu ne soient trop collés */ margin-bottom: 10px; /* Pour éviter que les éléments du menu ne soient trop collés */
} }
#choice #choice
{ {
float: left; float: left;
text-align: center; text-align: center;
background-color: #EEEEEE; background-color: #EEEEEE;
border: 2px solid black; border: 2px solid black;
height: 190px; height: 190px;
width: 20px; width: 20px;
} }
#map_canvas #map_canvas
{ {
width: 690px; width: 690px;
height: 350px; height: 350px;
margin-left: 125px; margin-left: 125px;
} }
#FlightPlan #FlightPlan
{ {
float: right; float: right;
width: 135px; /* Très important : donner une taille au menu */ width: 135px; /* Très important : donner une taille au menu */
height: 345px; height: 345px;
border: 2px solid black; border: 2px solid black;
background-color: #EEEEEE; background-color: #EEEEEE;
} }
#ControlPanel #ControlPanel
{ {
float: left; float: left;
text-align: center; text-align: center;
height: 150px; height: 150px;
width: 600px; width: 600px;
border: 2px solid black; border: 2px solid black;
background-color: #EEEEEE; background-color: #EEEEEE;
} }
#FlightParams #FlightParams
{ {
text-align: center; text-align: center;
float: right; float: right;
height: 150px; height: 150px;
width: 350px; width: 350px;
border: 2px solid black; border: 2px solid black;
background-color: #EEEEEE; background-color: #EEEEEE;
} }
table table
{ {
margin-left: 20px; margin-left: 20px;
margin-bottom: 20px; margin-bottom: 20px;
} }
@@ -1,34 +1,34 @@
/*--------------------------------------------------| /*--------------------------------------------------|
| dTree 2.05 | www.destroydrop.com/javascript/tree/ | | dTree 2.05 | www.destroydrop.com/javascript/tree/ |
|---------------------------------------------------| |---------------------------------------------------|
| Copyright (c) 2002-2003 Geir Landrö | | Copyright (c) 2002-2003 Geir Landrö |
|--------------------------------------------------*/ |--------------------------------------------------*/
.dtree { .dtree {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 11px; font-size: 11px;
color: #666; color: #666;
white-space: nowrap; white-space: nowrap;
} }
.dtree img { .dtree img {
border: 0px; border: 0px;
vertical-align: middle; vertical-align: middle;
} }
.dtree a { .dtree a {
color: #333; color: #333;
text-decoration: none; text-decoration: none;
} }
.dtree a.node, .dtree a.nodeSel { .dtree a.node, .dtree a.nodeSel {
white-space: nowrap; white-space: nowrap;
padding: 1px 2px 1px 2px; padding: 1px 2px 1px 2px;
} }
.dtree a.node:hover, .dtree a.nodeSel:hover { .dtree a.node:hover, .dtree a.nodeSel:hover {
color: #333; color: #333;
text-decoration: underline; text-decoration: underline;
} }
.dtree a.nodeSel { .dtree a.nodeSel {
background-color: #c0d2ec; background-color: #c0d2ec;
} }
.dtree .clip { .dtree .clip {
overflow: hidden; overflow: hidden;
} }
@@ -1,3 +1,3 @@
Manifest-Version: 1.0 Manifest-Version: 1.0
Class-Path: Class-Path:
@@ -1,24 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<conf_pow author="genin"> <conf_pow author="genin">
<portIvyToWeb>8535</portIvyToWeb> <portIvyToWeb>8535</portIvyToWeb>
<portWebToIvy>8536</portWebToIvy> <portWebToIvy>8536</portWebToIvy>
<sizeUdpTrame>1024</sizeUdpTrame> <sizeUdpTrame>1024</sizeUdpTrame>
<udpSocketTimeout>10000</udpSocketTimeout> <udpSocketTimeout>10000</udpSocketTimeout>
<dataBaseName>pow_sql</dataBaseName> <dataBaseName>pow_sql</dataBaseName>
<enableDatabase>true</enableDatabase><dbMode>silent</dbMode><dbUserName>pow_user</dbUserName> <enableDatabase>true</enableDatabase><dbMode>silent</dbMode><dbUserName>pow_user</dbUserName>
<dbPassword>pwdpow_user</dbPassword> <dbPassword>pwdpow_user</dbPassword>
<webAdminLogin>admin</webAdminLogin> <webAdminLogin>admin</webAdminLogin>
<mailWebAdmin>admin@pow.fr</mailWebAdmin> <mailWebAdmin>admin@pow.fr</mailWebAdmin>
<!--configuration for ivy client--><!-- period of time in millisec to reset the filter of waypoint_moved messages --> <!--configuration for ivy client--><!-- period of time in millisec to reset the filter of waypoint_moved messages -->
<time2resetFilter>1200000</time2resetFilter> <time2resetFilter>1200000</time2resetFilter>
<!-- period of time in millisec to send all the parameter values for a specific drone--> <!-- period of time in millisec to send all the parameter values for a specific drone-->
<timeToSendValues>60000</timeToSendValues> <timeToSendValues>60000</timeToSendValues>
<!-- timeout in interface --> <!-- timeout in interface -->
<!-- time to wait for the acknowledgement of an order --> <!-- time to wait for the acknowledgement of an order -->
<order_response_timeout>10000</order_response_timeout> <order_response_timeout>10000</order_response_timeout>
<!-- time to wait after a die event to remove the drone --> <!-- time to wait after a die event to remove the drone -->
<dieEventTimeoutTime>5000</dieEventTimeoutTime> <dieEventTimeoutTime>5000</dieEventTimeoutTime>
<!-- time to wait after receiving no data for a drone to remove the drone --> <!-- time to wait after receiving no data for a drone to remove the drone -->
<dataEventTimeoutTime>30000</dataEventTimeoutTime> <dataEventTimeoutTime>30000</dataEventTimeoutTime>
<!--period of time to check for dead ivy buses in serveur thread--><time2checkDeadBuses>30000</time2checkDeadBuses> <!--period of time to check for dead ivy buses in serveur thread--><time2checkDeadBuses>30000</time2checkDeadBuses>
</conf_pow> </conf_pow>
@@ -1,24 +1,24 @@
function DOMImplementation(sUrl, fCallback) { function DOMImplementation(sUrl, fCallback) {
var dom; var dom;
if(window.ActiveXObject) { if(window.ActiveXObject) {
dom = new ActiveXObject("Microsoft.XMLDOM"); dom = new ActiveXObject("Microsoft.XMLDOM");
dom.onreadystatechange = function() { dom.onreadystatechange = function() {
if(dom.readyState == 4) { if(dom.readyState == 4) {
//alert("win "+sUrl+" loaded"); //alert("win "+sUrl+" loaded");
fCallback(dom); fCallback(dom);
} }
}; };
} }
else if(document.implementation && document.implementation.createDocument) { else if(document.implementation && document.implementation.createDocument) {
dom = document.implementation.createDocument("", "", null); dom = document.implementation.createDocument("", "", null);
dom.onload = function() { dom.onload = function() {
//alert("other "+sUrl+" loaded"); //alert("other "+sUrl+" loaded");
fCallback(dom); fCallback(dom);
} }
} }
else { else {
alert("Votre navigateur ne gère pas l'importation de fichiers XML"); alert("Votre navigateur ne gère pas l'importation de fichiers XML");
return; return;
} }
dom.load(sUrl); dom.load(sUrl);
} }
@@ -1,20 +1,20 @@
function getXMLHttpRequest() { function getXMLHttpRequest() {
var xhr = null; var xhr = null;
if (window.XMLHttpRequest || window.ActiveXObject) { if (window.XMLHttpRequest || window.ActiveXObject) {
if (window.ActiveXObject) { if (window.ActiveXObject) {
try { try {
xhr = new ActiveXObject("Msxml2.XMLHTTP"); xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) { } catch(e) {
xhr = new ActiveXObject("Microsoft.XMLHTTP"); xhr = new ActiveXObject("Microsoft.XMLHTTP");
} }
} else { } else {
xhr = new XMLHttpRequest(); xhr = new XMLHttpRequest();
} }
} else { } else {
alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest..."); alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest...");
return null; return null;
} }
return xhr; return xhr;
} }
@@ -1,97 +1,97 @@
// Browser Detect Lite v2.1.4 // Browser Detect Lite v2.1.4
// http://www.dithered.com/javascript/browser_detect/index.html // http://www.dithered.com/javascript/browser_detect/index.html
// modified by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM) // modified by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)
function BrowserDetectLite() { function BrowserDetectLite() {
var ua = navigator.userAgent.toLowerCase(); var ua = navigator.userAgent.toLowerCase();
// browser name // browser name
this.isGecko = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1); this.isGecko = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
this.isMozilla = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length); this.isMozilla = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
this.isNS = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) ); this.isNS = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
this.isIE = ( (ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) ); this.isIE = ( (ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) );
this.isSafari = (ua.indexOf('safari') != - 1); this.isSafari = (ua.indexOf('safari') != - 1);
this.isOpera = (ua.indexOf('opera') != -1); this.isOpera = (ua.indexOf('opera') != -1);
this.isKonqueror = (ua.indexOf('konqueror') != -1 && !this.isSafari); this.isKonqueror = (ua.indexOf('konqueror') != -1 && !this.isSafari);
this.isIcab = (ua.indexOf('icab') != -1); this.isIcab = (ua.indexOf('icab') != -1);
this.isAol = (ua.indexOf('aol') != -1); this.isAol = (ua.indexOf('aol') != -1);
// spoofing and compatible browsers // spoofing and compatible browsers
this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE); this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla); this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
// browser version // browser version
this.versionMinor = parseFloat(navigator.appVersion); this.versionMinor = parseFloat(navigator.appVersion);
// correct version number // correct version number
if (this.isNS && this.isGecko) { if (this.isNS && this.isGecko) {
this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) ); this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
} }
else if (this.isIE && this.versionMinor >= 4) { else if (this.isIE && this.versionMinor >= 4) {
this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) ); this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
} }
else if (this.isMozilla) { else if (this.isMozilla) {
this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ); this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
} }
else if (this.isSafari) { else if (this.isSafari) {
this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) ); this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
} }
else if (this.isOpera) { else if (this.isOpera) {
if (ua.indexOf('opera/') != -1) { if (ua.indexOf('opera/') != -1) {
this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/') + 6 ) ); this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/') + 6 ) );
} }
else { else {
this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) ); this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) );
} }
} }
else if (this.isKonqueror) { else if (this.isKonqueror) {
this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) ); this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
} }
else if (this.isIcab) { else if (this.isIcab) {
if (ua.indexOf('icab/') != -1) { if (ua.indexOf('icab/') != -1) {
this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab/') + 6 ) ); this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab/') + 6 ) );
} }
else { else {
this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab ') + 6 ) ); this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab ') + 6 ) );
} }
} }
this.versionMajor = parseInt(this.versionMinor); this.versionMajor = parseInt(this.versionMinor);
this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 ); this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
// dom support // dom support
this.isDOM1 = (document.getElementById); this.isDOM1 = (document.getElementById);
this.isDOM2Event = (document.addEventListener && document.removeEventListener); this.isDOM2Event = (document.addEventListener && document.removeEventListener);
// css compatibility mode // css compatibility mode
this.mode = document.compatMode ? document.compatMode : 'BackCompat'; this.mode = document.compatMode ? document.compatMode : 'BackCompat';
// platform // platform
this.isWin = (ua.indexOf('win') != -1); this.isWin = (ua.indexOf('win') != -1);
this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) ); this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
this.isMac = (ua.indexOf('mac') != -1); this.isMac = (ua.indexOf('mac') != -1);
this.isUnix = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1) this.isUnix = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
this.isLinux = (ua.indexOf('linux') != -1); this.isLinux = (ua.indexOf('linux') != -1);
// specific browser shortcuts // specific browser shortcuts
this.isNS4x = (this.isNS && this.versionMajor == 4); this.isNS4x = (this.isNS && this.versionMajor == 4);
this.isNS40x = (this.isNS4x && this.versionMinor < 4.5); this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7); this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
this.isNS4up = (this.isNS && this.versionMinor >= 4); this.isNS4up = (this.isNS && this.versionMinor >= 4);
this.isNS6x = (this.isNS && this.versionMajor == 6); this.isNS6x = (this.isNS && this.versionMajor == 6);
this.isNS6up = (this.isNS && this.versionMajor >= 6); this.isNS6up = (this.isNS && this.versionMajor >= 6);
this.isNS7x = (this.isNS && this.versionMajor == 7); this.isNS7x = (this.isNS && this.versionMajor == 7);
this.isNS7up = (this.isNS && this.versionMajor >= 7); this.isNS7up = (this.isNS && this.versionMajor >= 7);
this.isIE4x = (this.isIE && this.versionMajor == 4); this.isIE4x = (this.isIE && this.versionMajor == 4);
this.isIE4up = (this.isIE && this.versionMajor >= 4); this.isIE4up = (this.isIE && this.versionMajor >= 4);
this.isIE5x = (this.isIE && this.versionMajor == 5); this.isIE5x = (this.isIE && this.versionMajor == 5);
this.isIE55 = (this.isIE && this.versionMinor == 5.5); this.isIE55 = (this.isIE && this.versionMinor == 5.5);
this.isIE5up = (this.isIE && this.versionMajor >= 5); this.isIE5up = (this.isIE && this.versionMajor >= 5);
this.isIE6x = (this.isIE && this.versionMajor == 6); this.isIE6x = (this.isIE && this.versionMajor == 6);
this.isIE6up = (this.isIE && this.versionMajor >= 6); this.isIE6up = (this.isIE && this.versionMajor >= 6);
this.isIE4xMac = (this.isIE4x && this.isMac); this.isIE4xMac = (this.isIE4x && this.isMac);
} }
var browser = new BrowserDetectLite(); var browser = new BrowserDetectLite();
@@ -1,155 +1,155 @@
/* /*
Author : bieler batiste Author : bieler batiste
Company : doSimple : http://www.dosimple.ch Company : doSimple : http://www.dosimple.ch
send me a mail for more informations : faden@PASDEPOURRIELaltern.org - remove ( PASDEPOURRIEL ) send me a mail for more informations : faden@PASDEPOURRIELaltern.org - remove ( PASDEPOURRIEL )
Short javascript function to create and handle a CSS navigation menu
Copyright (C) 2004 Bieler Batiste
This library 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; either
version 2.1 of the License, or (at your option) any later version.
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.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// the timeout for the menu
var timeout = 100;
// not very clean but simple
// the function can be run in the HTML for faster display
// window.onload=initMenu;
// creat timeout variables for list item
// it's for avoid some warning with IE
for( var i = 0; i < 100; i++ )
{
eval("var timeoutli" + i + " = false;");
}
// this fonction apply the CSS style and the event
function initMenu()
{
// a test to avoid some browser like IE4, Opera 6, and IE Mac
if ( browser.isDOM1
&& !( browser.isMac && browser.isIE )
&& !( browser.isOpera && browser.versionMajor < 7 )
&& !( browser.isIE && browser.versionMajor < 5 ) )
{
// get some element
var menu = document.getElementById('menu'); // the root element
var lis = menu.getElementsByTagName('li'); // all the li
// change the class name of the menu,
// it's usefull for compatibility with old browser
menu.className='menu';
// i am searching for ul element in li element
for ( var i=0; i<lis.length; i++ )
{
// is there a ul element ?
if ( lis.item(i).getElementsByTagName('ul').length > 0 )
{
// improve IE key navigation
if ( browser.isIE )
{
addAnEvent(lis.item(i),'keyup',show);
}
// link events to list item
addAnEvent(lis.item(i),'mouseover',show);
addAnEvent(lis.item(i),'mouseout',timeoutHide);
addAnEvent(lis.item(i),'blur',timeoutHide);
addAnEvent(lis.item(i),'focus',show);
// add an id to list item
lis.item(i).setAttribute( 'id', "li"+i );
}
}
}
}
Short javascript function to create and handle a CSS navigation menu
Copyright (C) 2004 Bieler Batiste
function addAnEvent( target, eventName, functionName )
{ This library is free software; you can redistribute it and/or
// apply the method to IE modify it under the terms of the GNU Lesser General Public
if ( browser.isIE ) License as published by the Free Software Foundation; either
{ version 2.1 of the License, or (at your option) any later version.
//attachEvent dont work properly with this
eval('target.on'+eventName+'=functionName'); This library is distributed in the hope that it will be useful,
} but WITHOUT ANY WARRANTY; without even the implied warranty of
// apply the method to DOM compliant browsers MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
else Lesser General Public License for more details.
{
target.addEventListener( eventName , functionName , true ); // true is important for Opera7 You should have received a copy of the GNU Lesser General Public
} License along with this library; if not, write to the Free Software
} Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// hide the first ul element of the current element
function timeoutHide() // the timeout for the menu
{ var timeout = 100;
// start the timeout
eval( "timeout" + this.id + " = window.setTimeout('hideUlUnder( \"" + this.id + "\" )', " + timeout + " );"); // not very clean but simple
} // the function can be run in the HTML for faster display
// window.onload=initMenu;
// hide the ul elements under the element identified by id
function hideUlUnder( id ) // creat timeout variables for list item
{ // it's for avoid some warning with IE
document.getElementById(id).getElementsByTagName('ul')[0].style['visibility'] = 'hidden'; for( var i = 0; i < 100; i++ )
} {
eval("var timeoutli" + i + " = false;");
// show the first ul element found under this element }
function show()
{ // this fonction apply the CSS style and the event
// show the sub menu function initMenu()
this.getElementsByTagName('ul')[0].style['visibility'] = 'visible'; {
var currentNode=this; // a test to avoid some browser like IE4, Opera 6, and IE Mac
while(currentNode) if ( browser.isDOM1
{ && !( browser.isMac && browser.isIE )
if( currentNode.nodeName=='LI') && !( browser.isOpera && browser.versionMajor < 7 )
{ && !( browser.isIE && browser.versionMajor < 5 ) )
// currentNode.getElementsByTagName('a')[0].className = 'linkOver'; {
} // get some element
currentNode=currentNode.parentNode; var menu = document.getElementById('menu'); // the root element
} var lis = menu.getElementsByTagName('li'); // all the li
// clear the timeout
eval ( "clearTimeout( timeout"+ this.id +");" ); // change the class name of the menu,
hideAllOthersUls( this ); // it's usefull for compatibility with old browser
} menu.className='menu';
// i am searching for ul element in li element
// hide all ul on the same level of this list item for ( var i=0; i<lis.length; i++ )
function hideAllOthersUls( currentLi ) {
{ // is there a ul element ?
var lis = currentLi.parentNode; if ( lis.item(i).getElementsByTagName('ul').length > 0 )
for ( var i=0; i<lis.childNodes.length; i++ ) {
{ // improve IE key navigation
if ( lis.childNodes[i].nodeName=='LI' && lis.childNodes[i].id != currentLi.id ) if ( browser.isIE )
{ {
hideUlUnderLi( lis.childNodes[i] ); addAnEvent(lis.item(i),'keyup',show);
} }
} // link events to list item
} addAnEvent(lis.item(i),'mouseover',show);
addAnEvent(lis.item(i),'mouseout',timeoutHide);
// hide all the ul wich are in the li element addAnEvent(lis.item(i),'blur',timeoutHide);
function hideUlUnderLi( li ) addAnEvent(lis.item(i),'focus',show);
{
var as = li.getElementsByTagName('a'); // add an id to list item
for ( var i=0; i<as.length; i++ ) lis.item(i).setAttribute( 'id', "li"+i );
{ }
as.item(i).className=""; }
} }
var uls = li.getElementsByTagName('ul'); }
for ( var i=0; i<uls.length; i++ )
{
uls.item(i).style['visibility'] = 'hidden';
}
} function addAnEvent( target, eventName, functionName )
{
// apply the method to IE
if ( browser.isIE )
{
//attachEvent dont work properly with this
eval('target.on'+eventName+'=functionName');
}
// apply the method to DOM compliant browsers
else
{
target.addEventListener( eventName , functionName , true ); // true is important for Opera7
}
}
// hide the first ul element of the current element
function timeoutHide()
{
// start the timeout
eval( "timeout" + this.id + " = window.setTimeout('hideUlUnder( \"" + this.id + "\" )', " + timeout + " );");
}
// hide the ul elements under the element identified by id
function hideUlUnder( id )
{
document.getElementById(id).getElementsByTagName('ul')[0].style['visibility'] = 'hidden';
}
// show the first ul element found under this element
function show()
{
// show the sub menu
this.getElementsByTagName('ul')[0].style['visibility'] = 'visible';
var currentNode=this;
while(currentNode)
{
if( currentNode.nodeName=='LI')
{
// currentNode.getElementsByTagName('a')[0].className = 'linkOver';
}
currentNode=currentNode.parentNode;
}
// clear the timeout
eval ( "clearTimeout( timeout"+ this.id +");" );
hideAllOthersUls( this );
}
// hide all ul on the same level of this list item
function hideAllOthersUls( currentLi )
{
var lis = currentLi.parentNode;
for ( var i=0; i<lis.childNodes.length; i++ )
{
if ( lis.childNodes[i].nodeName=='LI' && lis.childNodes[i].id != currentLi.id )
{
hideUlUnderLi( lis.childNodes[i] );
}
}
}
// hide all the ul wich are in the li element
function hideUlUnderLi( li )
{
var as = li.getElementsByTagName('a');
for ( var i=0; i<as.length; i++ )
{
as.item(i).className="";
}
var uls = li.getElementsByTagName('ul');
for ( var i=0; i<uls.length; i++ )
{
uls.item(i).style['visibility'] = 'hidden';
}
}
@@ -1,110 +1,110 @@
var timeout = 100; var timeout = 100;
for( var i = 0; i < 100; i++ ) for( var i = 0; i < 100; i++ )
{ {
eval("var timeoutli" + i + " = false;"); eval("var timeoutli" + i + " = false;");
} }
function initMenu2(){ function initMenu2(){
if ( browser.isDOM1 if ( browser.isDOM1
&& !( browser.isMac && browser.isIE ) && !( browser.isMac && browser.isIE )
&& !( browser.isOpera && browser.versionMajor < 7 ) && !( browser.isOpera && browser.versionMajor < 7 )
&& !( browser.isIE && browser.versionMajor < 5 ) ) && !( browser.isIE && browser.versionMajor < 5 ) )
{ {
var menu2 = document.getElementById('menu2'); var menu2 = document.getElementById('menu2');
var lis2 = menu2.getElementsByTagName('li'); var lis2 = menu2.getElementsByTagName('li');
menu2.className='menu2'; menu2.className='menu2';
for ( var i=0; i<lis2.length; i++ ) for ( var i=0; i<lis2.length; i++ )
{ {
if ( lis2.item(i).getElementsByTagName('ul').length > 0 ) if ( lis2.item(i).getElementsByTagName('ul').length > 0 )
{ {
if ( browser.isIE ) if ( browser.isIE )
{ {
addAnEvent(lis2.item(i),'keyup',show); addAnEvent(lis2.item(i),'keyup',show);
} }
addAnEvent(lis2.item(i),'mouseover',show); addAnEvent(lis2.item(i),'mouseover',show);
addAnEvent(lis2.item(i),'mouseout',timeoutHide); addAnEvent(lis2.item(i),'mouseout',timeoutHide);
addAnEvent(lis2.item(i),'blur',timeoutHide); addAnEvent(lis2.item(i),'blur',timeoutHide);
addAnEvent(lis2.item(i),'focus',show); addAnEvent(lis2.item(i),'focus',show);
lis2.item(i).setAttribute( 'id', "li2"+i ); lis2.item(i).setAttribute( 'id', "li2"+i );
} }
} }
} }
} }
function addAnEvent( target, eventName, functionName ) function addAnEvent( target, eventName, functionName )
{ {
if ( browser.isIE ) if ( browser.isIE )
{
eval('target.on'+eventName+'=functionName');
}
else
{ {
eval('target.on'+eventName+'=functionName');
}
else
{
target.addEventListener( eventName , functionName , true ); target.addEventListener( eventName , functionName , true );
} }
} }
function timeoutHide() function timeoutHide()
{ {
eval( "timeout" + this.id + " = window.setTimeout('hideUlUnder( \"" + this.id + "\" )', " + timeout + " );"); eval( "timeout" + this.id + " = window.setTimeout('hideUlUnder( \"" + this.id + "\" )', " + timeout + " );");
} }
// hide the ul elements under the element identified by id // hide the ul elements under the element identified by id
function hideUlUnder( id ) function hideUlUnder( id )
{ {
document.getElementById(id).getElementsByTagName('ul')[0].style['visibility'] = 'hidden'; document.getElementById(id).getElementsByTagName('ul')[0].style['visibility'] = 'hidden';
} }
// show the first ul element found under this element // show the first ul element found under this element
function show() function show()
{ {
// show the sub menu // show the sub menu
this.getElementsByTagName('ul')[0].style['visibility'] = 'visible'; this.getElementsByTagName('ul')[0].style['visibility'] = 'visible';
var currentNode=this; var currentNode=this;
while(currentNode) while(currentNode)
{ {
if( currentNode.nodeName=='LI') if( currentNode.nodeName=='LI')
{ {
// currentNode.getElementsByTagName('a')[0].className = 'linkOver'; // currentNode.getElementsByTagName('a')[0].className = 'linkOver';
} }
currentNode=currentNode.parentNode; currentNode=currentNode.parentNode;
} }
// clear the timeout // clear the timeout
eval ( "clearTimeout( timeout"+ this.id +");" ); eval ( "clearTimeout( timeout"+ this.id +");" );
hideAllOthersUls( this ); hideAllOthersUls( this );
} }
// hide all ul on the same level of this list item // hide all ul on the same level of this list item
function hideAllOthersUls( currentLi ) function hideAllOthersUls( currentLi )
{ {
var lis = currentLi.parentNode; var lis = currentLi.parentNode;
for ( var i=0; i<lis.childNodes.length; i++ ) for ( var i=0; i<lis.childNodes.length; i++ )
{ {
if ( lis.childNodes[i].nodeName=='LI' && lis.childNodes[i].id != currentLi.id ) if ( lis.childNodes[i].nodeName=='LI' && lis.childNodes[i].id != currentLi.id )
{ {
hideUlUnderLi( lis.childNodes[i] ); hideUlUnderLi( lis.childNodes[i] );
} }
} }
} }
// hide all the ul wich are in the li element // hide all the ul wich are in the li element
function hideUlUnderLi( li ) function hideUlUnderLi( li )
{ {
var as = li.getElementsByTagName('a'); var as = li.getElementsByTagName('a');
for ( var i=0; i<as.length; i++ ) for ( var i=0; i<as.length; i++ )
{ {
as.item(i).className=""; as.item(i).className="";
} }
var uls = li.getElementsByTagName('ul'); var uls = li.getElementsByTagName('ul');
for ( var i=0; i<uls.length; i++ ) for ( var i=0; i<uls.length; i++ )
{ {
uls.item(i).style['visibility'] = 'hidden'; uls.item(i).style['visibility'] = 'hidden';
} }
} }
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,50 +1,50 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.client; package nl.justobjects.pushlet.client;
import nl.justobjects.pushlet.core.Event; import nl.justobjects.pushlet.core.Event;
import nl.justobjects.pushlet.core.Protocol; import nl.justobjects.pushlet.core.Protocol;
/** /**
* Interface for listener of the PushletClient object. * Interface for listener of the PushletClient object.
* *
* @version $Id: PushletClientListener.java,v 1.5 2005/02/21 11:50:37 justb Exp $ * @version $Id: PushletClientListener.java,v 1.5 2005/02/21 11:50:37 justb Exp $
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
**/ **/
public interface PushletClientListener extends Protocol { public interface PushletClientListener extends Protocol {
/** Abort event from server. */ /** Abort event from server. */
public void onAbort(Event theEvent); public void onAbort(Event theEvent);
/** Data event from server. */ /** Data event from server. */
public void onData(Event theEvent); public void onData(Event theEvent);
/** Heartbeat event from server. */ /** Heartbeat event from server. */
public void onHeartbeat(Event theEvent); public void onHeartbeat(Event theEvent);
/** Error occurred. */ /** Error occurred. */
public void onError(String message); public void onError(String message);
} }
/* /*
* $Log: PushletClientListener.java,v $ * $Log: PushletClientListener.java,v $
* Revision 1.5 2005/02/21 11:50:37 justb * Revision 1.5 2005/02/21 11:50:37 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.4 2005/02/15 15:46:31 justb * Revision 1.4 2005/02/15 15:46:31 justb
* client API improves * client API improves
* *
* Revision 1.3 2004/10/24 12:58:18 justb * Revision 1.3 2004/10/24 12:58:18 justb
* revised client and test classes for new protocol * revised client and test classes for new protocol
* *
* Revision 1.2 2004/09/03 22:35:37 justb * Revision 1.2 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.1 2004/03/10 20:14:17 justb * Revision 1.1 2004/03/10 20:14:17 justb
* renamed all *JavaPushletClient* to *PushletClient* * renamed all *JavaPushletClient* to *PushletClient*
* *
* Revision 1.3 2003/08/15 08:37:40 justb * Revision 1.3 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* *
*/ */
@@ -1,203 +1,203 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.core; package nl.justobjects.pushlet.core;
import nl.justobjects.pushlet.util.Log; import nl.justobjects.pushlet.util.Log;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Iterator; import java.util.Iterator;
/** /**
* Generic implementation of ClientAdapter for browser clients. * Generic implementation of ClientAdapter for browser clients.
* *
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
* @version $Id: BrowserAdapter.java,v 1.6 2007/11/09 13:15:35 justb Exp $ * @version $Id: BrowserAdapter.java,v 1.6 2007/11/09 13:15:35 justb Exp $
*/ */
public class BrowserAdapter implements ClientAdapter, Protocol { public class BrowserAdapter implements ClientAdapter, Protocol {
public static final String START_DOCUMENT = public static final String START_DOCUMENT =
"<html><head><meta http-equiv=\"Pragma\" content=\"no-cache\"><meta http-equiv=\"Expires\" content=\"Tue, 31 Dec 1997 23:59:59 GMT\"></head>" "<html><head><meta http-equiv=\"Pragma\" content=\"no-cache\"><meta http-equiv=\"Expires\" content=\"Tue, 31 Dec 1997 23:59:59 GMT\"></head>"
+ "<body>" + "<body>"
+ "\n<script language=\"JavaScript\"> var url=\" \"; \nfunction refresh() { document.location.href=url; }</script>"; + "\n<script language=\"JavaScript\"> var url=\" \"; \nfunction refresh() { document.location.href=url; }</script>";
public static final String END_DOCUMENT = "</body></html>"; public static final String END_DOCUMENT = "</body></html>";
private PrintWriter servletOut; private PrintWriter servletOut;
private HttpServletResponse servletRsp; private HttpServletResponse servletRsp;
private int bytesSent; private int bytesSent;
/** /**
* Constructor. * Constructor.
*/ */
public BrowserAdapter(HttpServletResponse aServletResponse) { public BrowserAdapter(HttpServletResponse aServletResponse) {
servletRsp = aServletResponse; servletRsp = aServletResponse;
} }
/** /**
* Generic init. * Generic init.
*/ */
public void start() throws IOException { public void start() throws IOException {
// Keep servlet request/response objects until page ends in stop() // Keep servlet request/response objects until page ends in stop()
// Content type as HTML // Content type as HTML
servletRsp.setStatus(HttpServletResponse.SC_OK); servletRsp.setStatus(HttpServletResponse.SC_OK);
servletRsp.setContentType("text/html;charset=UTF-8"); servletRsp.setContentType("text/html;charset=UTF-8");
// http://www.junlu.com/msg/45902.html // http://www.junlu.com/msg/45902.html
// Log.debug("bufsize=" + aRsp.getBufferSize()); // Log.debug("bufsize=" + aRsp.getBufferSize());
servletOut = servletRsp.getWriter(); servletOut = servletRsp.getWriter();
send(START_DOCUMENT); send(START_DOCUMENT);
} }
/** /**
* Push Event to client. * Push Event to client.
*/ */
public void push(Event anEvent) throws IOException { public void push(Event anEvent) throws IOException {
Log.debug("BCA event=" + anEvent.toXML()); Log.debug("BCA event=" + anEvent.toXML());
// Check if we should refresh // Check if we should refresh
if (anEvent.getEventType().equals(Protocol.E_REFRESH)) { if (anEvent.getEventType().equals(Protocol.E_REFRESH)) {
// Append refresh and tail of HTML document // Append refresh and tail of HTML document
// Construct the JS callback line to be sent as last line of doc. // Construct the JS callback line to be sent as last line of doc.
// This will refresh the request using the unique id to determine // This will refresh the request using the unique id to determine
// the subscriber instance on the server. The client will wait for // the subscriber instance on the server. The client will wait for
// a number of milliseconds. // a number of milliseconds.
long refreshWaitMillis = Long.parseLong(anEvent.getField(P_WAIT)); long refreshWaitMillis = Long.parseLong(anEvent.getField(P_WAIT));
// Create servlet request for requesting next events (refresh) // Create servlet request for requesting next events (refresh)
String url = anEvent.getField(P_URL); String url = anEvent.getField(P_URL);
String jsRefreshTrigger = "\n<script language=\"JavaScript\">url=\'" + url + "\';\n setTimeout(\"refresh()\", " + refreshWaitMillis + ");\n</script>"; String jsRefreshTrigger = "\n<script language=\"JavaScript\">url=\'" + url + "\';\n setTimeout(\"refresh()\", " + refreshWaitMillis + ");\n</script>";
send(jsRefreshTrigger + END_DOCUMENT); send(jsRefreshTrigger + END_DOCUMENT);
} else { } else {
send(event2JavaScript(anEvent)); send(event2JavaScript(anEvent));
} }
} }
/** /**
* End HTML page in client browser. * End HTML page in client browser.
*/ */
public void stop() { public void stop() {
// To be garbage collected if adapter remains active // To be garbage collected if adapter remains active
servletOut = null; servletOut = null;
} }
/** /**
* Send any string to browser. * Send any string to browser.
*/ */
protected void send(String s) throws IOException { protected void send(String s) throws IOException {
// Send string to browser. // Send string to browser.
// Log.debug("Adapter: sending: " + s); // Log.debug("Adapter: sending: " + s);
if (servletOut == null) { if (servletOut == null) {
throw new IOException("Client adapter was stopped"); throw new IOException("Client adapter was stopped");
} }
servletOut.print(s); servletOut.print(s);
servletOut.flush(); servletOut.flush();
// Note: this doesn't seem to have effect // Note: this doesn't seem to have effect
// in Tomcat 4/5 if the client already disconnected. // in Tomcat 4/5 if the client already disconnected.
servletRsp.flushBuffer(); servletRsp.flushBuffer();
bytesSent += s.length(); bytesSent += s.length();
Log.debug("bytesSent= " + bytesSent); Log.debug("bytesSent= " + bytesSent);
// Log.debug("BCA sent event: " + s); // Log.debug("BCA sent event: " + s);
} }
/** /**
* Converts the Java Event to a JavaScript function call in browser page. * Converts the Java Event to a JavaScript function call in browser page.
*/ */
protected String event2JavaScript(Event event) throws IOException { protected String event2JavaScript(Event event) throws IOException {
// Convert the event to a comma-separated string. // Convert the event to a comma-separated string.
String jsArgs = ""; String jsArgs = "";
for (Iterator iter = event.getFieldNames(); iter.hasNext();) { for (Iterator iter = event.getFieldNames(); iter.hasNext();) {
String name = (String) iter.next(); String name = (String) iter.next();
String value = event.getField(name); String value = event.getField(name);
String nextArgument = (jsArgs.equals("") ? "" : ",") + "'" + name + "'" + ", \"" + value + "\""; String nextArgument = (jsArgs.equals("") ? "" : ",") + "'" + name + "'" + ", \"" + value + "\"";
jsArgs += nextArgument; jsArgs += nextArgument;
} }
// Construct and return the function call */ // Construct and return the function call */
return "<script language=\"JavaScript\">parent.push(" + jsArgs + ");</script>"; return "<script language=\"JavaScript\">parent.push(" + jsArgs + ");</script>";
} }
} }
/* /*
* $Log: BrowserAdapter.java,v $ * $Log: BrowserAdapter.java,v $
* Revision 1.6 2007/11/09 13:15:35 justb * Revision 1.6 2007/11/09 13:15:35 justb
* add charset=UTF-8 in returned HTTP content types * add charset=UTF-8 in returned HTTP content types
* *
* Revision 1.5 2006/05/15 11:52:53 justb * Revision 1.5 2006/05/15 11:52:53 justb
* updates mainly for AJAX client * updates mainly for AJAX client
* *
* Revision 1.4 2006/05/06 00:10:11 justb * Revision 1.4 2006/05/06 00:10:11 justb
* various chgs but not too serious... * various chgs but not too serious...
* *
* Revision 1.3 2005/02/28 12:45:59 justb * Revision 1.3 2005/02/28 12:45:59 justb
* introduced Command class * introduced Command class
* *
* Revision 1.2 2005/02/21 11:50:44 justb * Revision 1.2 2005/02/21 11:50:44 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.1 2005/02/18 10:07:23 justb * Revision 1.1 2005/02/18 10:07:23 justb
* many renamings of classes (make names compact) * many renamings of classes (make names compact)
* *
* Revision 1.12 2005/02/15 13:30:23 justb * Revision 1.12 2005/02/15 13:30:23 justb
* changes for Tomcat buffering (now working in tc4 and 5.0) * changes for Tomcat buffering (now working in tc4 and 5.0)
* *
* Revision 1.11 2005/01/24 22:45:58 justb * Revision 1.11 2005/01/24 22:45:58 justb
* getting safari to work * getting safari to work
* *
* Revision 1.10 2005/01/18 16:46:27 justb * Revision 1.10 2005/01/18 16:46:27 justb
* buffer size setting ignored by tomcat workings * buffer size setting ignored by tomcat workings
* *
* Revision 1.9 2004/10/24 12:58:18 justb * Revision 1.9 2004/10/24 12:58:18 justb
* revised client and test classes for new protocol * revised client and test classes for new protocol
* *
* Revision 1.8 2004/09/20 22:01:38 justb * Revision 1.8 2004/09/20 22:01:38 justb
* more changes for new protocol * more changes for new protocol
* *
* Revision 1.7 2004/09/03 22:35:37 justb * Revision 1.7 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.6 2004/08/15 16:00:15 justb * Revision 1.6 2004/08/15 16:00:15 justb
* enhancements to pull mode * enhancements to pull mode
* *
* Revision 1.5 2004/08/13 23:36:05 justb * Revision 1.5 2004/08/13 23:36:05 justb
* rewrite of Pullet into Pushlet "pull" mode * rewrite of Pullet into Pushlet "pull" mode
* *
* Revision 1.4 2003/08/15 08:37:40 justb * Revision 1.4 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.3 2003/08/12 09:57:05 justb * Revision 1.3 2003/08/12 09:57:05 justb
* replaced all print statements to Log.*() calls * replaced all print statements to Log.*() calls
* *
* Revision 1.2 2003/05/18 16:15:07 justb * Revision 1.2 2003/05/18 16:15:07 justb
* support for XML encoded Events * support for XML encoded Events
* *
* Revision 1.1.1.1 2002/09/24 21:02:30 justb * Revision 1.1.1.1 2002/09/24 21:02:30 justb
* import to sourceforge * import to sourceforge
* *
* Revision 1.1.1.1 2002/09/20 22:48:17 justb * Revision 1.1.1.1 2002/09/20 22:48:17 justb
* import to SF * import to SF
* *
* Revision 1.1.1.1 2002/09/20 14:19:02 justb * Revision 1.1.1.1 2002/09/20 14:19:02 justb
* first import into SF * first import into SF
* *
* Revision 1.5 2002/04/15 20:42:41 just * Revision 1.5 2002/04/15 20:42:41 just
* reformatting and renaming GuardedQueue to EventQueue * reformatting and renaming GuardedQueue to EventQueue
* *
* Revision 1.4 2000/12/27 22:39:35 just * Revision 1.4 2000/12/27 22:39:35 just
* no message * no message
* *
* Revision 1.3 2000/10/30 14:15:47 just * Revision 1.3 2000/10/30 14:15:47 just
* no message * no message
* *
* *
*/ */
@@ -1,72 +1,72 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.core; package nl.justobjects.pushlet.core;
import java.io.IOException; import java.io.IOException;
/** /**
* Adapter interface for encapsulation of specific HTTP clients. * Adapter interface for encapsulation of specific HTTP clients.
* *
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
* @version $Id: ClientAdapter.java,v 1.8 2007/11/23 14:33:07 justb Exp $ * @version $Id: ClientAdapter.java,v 1.8 2007/11/23 14:33:07 justb Exp $
*/ */
public interface ClientAdapter { public interface ClientAdapter {
/** /**
* Start event push. * Start event push.
*/ */
public void start() throws IOException; public void start() throws IOException;
/** /**
* Push single Event to client. * Push single Event to client.
*/ */
public void push(Event anEvent) throws IOException; public void push(Event anEvent) throws IOException;
/** /**
* Stop event push. * Stop event push.
*/ */
public void stop() throws IOException; public void stop() throws IOException;
} }
/* /*
* $Log: ClientAdapter.java,v $ * $Log: ClientAdapter.java,v $
* Revision 1.8 2007/11/23 14:33:07 justb * Revision 1.8 2007/11/23 14:33:07 justb
* core classes now configurable through factory * core classes now configurable through factory
* *
* Revision 1.7 2005/02/28 12:45:59 justb * Revision 1.7 2005/02/28 12:45:59 justb
* introduced Command class * introduced Command class
* *
* Revision 1.6 2005/02/21 11:50:45 justb * Revision 1.6 2005/02/21 11:50:45 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.5 2005/02/18 10:07:23 justb * Revision 1.5 2005/02/18 10:07:23 justb
* many renamings of classes (make names compact) * many renamings of classes (make names compact)
* *
* Revision 1.4 2004/09/03 22:35:37 justb * Revision 1.4 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.3 2003/08/15 08:37:40 justb * Revision 1.3 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.2 2003/05/18 16:15:08 justb * Revision 1.2 2003/05/18 16:15:08 justb
* support for XML encoded Events * support for XML encoded Events
* *
* Revision 1.1.1.1 2002/09/24 21:02:30 justb * Revision 1.1.1.1 2002/09/24 21:02:30 justb
* import to sourceforge * import to sourceforge
* *
* Revision 1.1.1.1 2002/09/20 22:48:17 justb * Revision 1.1.1.1 2002/09/20 22:48:17 justb
* import to SF * import to SF
* *
* Revision 1.1.1.1 2002/09/20 14:19:03 justb * Revision 1.1.1.1 2002/09/20 14:19:03 justb
* first import into SF * first import into SF
* *
* Revision 1.3 2002/04/15 20:42:41 just * Revision 1.3 2002/04/15 20:42:41 just
* reformatting and renaming GuardedQueue to EventQueue * reformatting and renaming GuardedQueue to EventQueue
* *
* Revision 1.2 2000/08/21 20:48:29 just * Revision 1.2 2000/08/21 20:48:29 just
* added CVS log and id tags plus copyrights * added CVS log and id tags plus copyrights
* *
* *
*/ */
@@ -1,184 +1,184 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.core; package nl.justobjects.pushlet.core;
import nl.justobjects.pushlet.util.Sys; import nl.justobjects.pushlet.util.Sys;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
/** /**
* Represents the event data. * Represents the event data.
* *
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
* @version $Id: Event.java,v 1.13 2007/11/23 14:33:07 justb Exp $ * @version $Id: Event.java,v 1.13 2007/11/23 14:33:07 justb Exp $
*/ */
public class Event implements Protocol, Serializable { public class Event implements Protocol, Serializable {
protected Map attributes = new HashMap(3); protected Map attributes = new HashMap(3);
public Event(String anEventType) { public Event(String anEventType) {
this(anEventType, null); this(anEventType, null);
} }
public Event(String anEventType, Map theAttributes) { public Event(String anEventType, Map theAttributes) {
if (theAttributes != null) { if (theAttributes != null) {
setAttrs(theAttributes); setAttrs(theAttributes);
} }
// Set required field event type // Set required field event type
setField(P_EVENT, anEventType); setField(P_EVENT, anEventType);
// Set time in seconds since 1970 // Set time in seconds since 1970
setField(P_TIME, System.currentTimeMillis() / 1000); setField(P_TIME, System.currentTimeMillis() / 1000);
} }
public Event(Map theAttributes) { public Event(Map theAttributes) {
if (!theAttributes.containsKey(P_EVENT)) { if (!theAttributes.containsKey(P_EVENT)) {
throw new IllegalArgumentException(P_EVENT + " not found in attributes"); throw new IllegalArgumentException(P_EVENT + " not found in attributes");
} }
setAttrs(theAttributes); setAttrs(theAttributes);
} }
public static Event createDataEvent(String aSubject) { public static Event createDataEvent(String aSubject) {
return createDataEvent(aSubject, null); return createDataEvent(aSubject, null);
} }
public static Event createDataEvent(String aSubject, Map theAttributes) { public static Event createDataEvent(String aSubject, Map theAttributes) {
Event dataEvent = new Event(E_DATA, theAttributes); Event dataEvent = new Event(E_DATA, theAttributes);
dataEvent.setField(P_SUBJECT, aSubject); dataEvent.setField(P_SUBJECT, aSubject);
return dataEvent; return dataEvent;
} }
public String getEventType() { public String getEventType() {
return getField(P_EVENT); return getField(P_EVENT);
} }
public String getSubject() { public String getSubject() {
return getField(P_SUBJECT); return getField(P_SUBJECT);
} }
public void setField(String name, String value) { public void setField(String name, String value) {
attributes.put(name, value); attributes.put(name, value);
} }
public void setField(String name, int value) { public void setField(String name, int value) {
attributes.put(name, value + ""); attributes.put(name, value + "");
} }
public void setField(String name, long value) { public void setField(String name, long value) {
attributes.put(name, value + ""); attributes.put(name, value + "");
} }
public String getField(String name) { public String getField(String name) {
return (String) attributes.get(name); return (String) attributes.get(name);
} }
/** /**
* Return field; if null return default. * Return field; if null return default.
*/ */
public String getField(String name, String aDefault) { public String getField(String name, String aDefault) {
String result = getField(name); String result = getField(name);
return result == null ? aDefault : result; return result == null ? aDefault : result;
} }
public Iterator getFieldNames() { public Iterator getFieldNames() {
return attributes.keySet().iterator(); return attributes.keySet().iterator();
} }
public String toString() { public String toString() {
return attributes.toString(); return attributes.toString();
} }
/** /**
* Convert to HTTP query string. * Convert to HTTP query string.
*/ */
public String toQueryString() { public String toQueryString() {
String queryString = ""; String queryString = "";
String amp = ""; String amp = "";
for (Iterator iter = getFieldNames(); iter.hasNext();) { for (Iterator iter = getFieldNames(); iter.hasNext();) {
String nextAttrName = (String) iter.next(); String nextAttrName = (String) iter.next();
String nextAttrValue = getField(nextAttrName); String nextAttrValue = getField(nextAttrName);
queryString = queryString + amp + nextAttrName + "=" + nextAttrValue; queryString = queryString + amp + nextAttrName + "=" + nextAttrValue;
// After first add "&". // After first add "&".
amp = "&"; amp = "&";
} }
return queryString; return queryString;
} }
public String toXML(boolean strict) { public String toXML(boolean strict) {
String xmlString = "<event "; String xmlString = "<event ";
for (Iterator iter = getFieldNames(); iter.hasNext();) { for (Iterator iter = getFieldNames(); iter.hasNext();) {
String nextAttrName = (String) iter.next(); String nextAttrName = (String) iter.next();
String nextAttrValue = getField(nextAttrName); String nextAttrValue = getField(nextAttrName);
xmlString = xmlString + nextAttrName + "=\"" + (strict ? Sys.forHTMLTag(nextAttrValue) : nextAttrValue) + "\" "; xmlString = xmlString + nextAttrName + "=\"" + (strict ? Sys.forHTMLTag(nextAttrValue) : nextAttrValue) + "\" ";
} }
xmlString += "/>"; xmlString += "/>";
return xmlString; return xmlString;
} }
public String toXML() { public String toXML() {
return toXML(false); return toXML(false);
} }
public Object clone() { public Object clone() {
// Clone the Event by using copy constructor // Clone the Event by using copy constructor
return new Event(attributes); return new Event(attributes);
} }
/** /**
* Copy given attributes into event attributes * Copy given attributes into event attributes
*/ */
private void setAttrs(Map theAttributes) { private void setAttrs(Map theAttributes) {
attributes.putAll(theAttributes); attributes.putAll(theAttributes);
} }
} }
/* /*
* $Log: Event.java,v $ * $Log: Event.java,v $
* Revision 1.13 2007/11/23 14:33:07 justb * Revision 1.13 2007/11/23 14:33:07 justb
* core classes now configurable through factory * core classes now configurable through factory
* *
* Revision 1.12 2006/05/15 11:52:53 justb * Revision 1.12 2006/05/15 11:52:53 justb
* updates mainly for AJAX client * updates mainly for AJAX client
* *
* Revision 1.11 2006/05/06 00:06:28 justb * Revision 1.11 2006/05/06 00:06:28 justb
* first rough version AJAX client * first rough version AJAX client
* *
* Revision 1.10 2005/02/21 11:50:46 justb * Revision 1.10 2005/02/21 11:50:46 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.9 2005/02/20 13:05:32 justb * Revision 1.9 2005/02/20 13:05:32 justb
* removed the Postlet (integrated in Pushlet protocol) * removed the Postlet (integrated in Pushlet protocol)
* *
* Revision 1.8 2005/02/15 13:29:24 justb * Revision 1.8 2005/02/15 13:29:24 justb
* add toQueryString() * add toQueryString()
* *
* Revision 1.7 2005/01/18 16:47:10 justb * Revision 1.7 2005/01/18 16:47:10 justb
* protocol changes for v2 and publishing from pushlet client * protocol changes for v2 and publishing from pushlet client
* *
* Revision 1.6 2005/01/13 14:47:15 justb * Revision 1.6 2005/01/13 14:47:15 justb
* control evt: send response on same (control) connection * control evt: send response on same (control) connection
* *
* Revision 1.5 2004/09/03 22:35:37 justb * Revision 1.5 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.4 2004/08/15 16:00:15 justb * Revision 1.4 2004/08/15 16:00:15 justb
* enhancements to pull mode * enhancements to pull mode
* *
* Revision 1.3 2003/08/15 08:37:40 justb * Revision 1.3 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.2 2003/05/18 16:15:08 justb * Revision 1.2 2003/05/18 16:15:08 justb
* support for XML encoded Events * support for XML encoded Events
* *
* Revision 1.1.1.1 2002/09/24 21:02:30 justb * Revision 1.1.1.1 2002/09/24 21:02:30 justb
* import to sourceforge * import to sourceforge
* *
*/ */
@@ -1,185 +1,185 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.core; package nl.justobjects.pushlet.core;
import nl.justobjects.pushlet.util.Log; import nl.justobjects.pushlet.util.Log;
/** /**
* Abstract Event source from which Events are pulled. * Abstract Event source from which Events are pulled.
* *
* @version $Id: EventPullSource.java,v 1.15 2007/11/23 14:33:07 justb Exp $ * @version $Id: EventPullSource.java,v 1.15 2007/11/23 14:33:07 justb Exp $
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
**/ **/
/** /**
* ABC for specifc EventPullSources. * ABC for specifc EventPullSources.
*/ */
abstract public class EventPullSource implements EventSource, Runnable { abstract public class EventPullSource implements EventSource, Runnable {
private volatile boolean alive = false; private volatile boolean alive = false;
private volatile boolean active = false; private volatile boolean active = false;
private static int threadNum = 0; private static int threadNum = 0;
private Thread thread; private Thread thread;
public EventPullSource() { public EventPullSource() {
} }
abstract protected long getSleepTime(); abstract protected long getSleepTime();
abstract protected Event pullEvent(); abstract protected Event pullEvent();
public void start() { public void start() {
thread = new Thread(this, "EventPullSource-" + (++threadNum)); thread = new Thread(this, "EventPullSource-" + (++threadNum));
thread.setDaemon(true); thread.setDaemon(true);
thread.start(); thread.start();
} }
public boolean isAlive() { public boolean isAlive() {
return alive; return alive;
} }
/** /**
* Stop the event generator thread. * Stop the event generator thread.
*/ */
public void stop() { public void stop() {
alive = false; alive = false;
if (thread != null) { if (thread != null) {
thread.interrupt(); thread.interrupt();
thread = null; thread = null;
} }
} }
/** /**
* Activate the event generator thread. * Activate the event generator thread.
*/ */
synchronized public void activate() { synchronized public void activate() {
if (active) { if (active) {
return; return;
} }
active = true; active = true;
if (!alive) { if (!alive) {
start(); start();
return; return;
} }
Log.debug(getClass().getName() + ": notifying..."); Log.debug(getClass().getName() + ": notifying...");
notifyAll(); notifyAll();
} }
/** /**
* Deactivate the event generator thread. * Deactivate the event generator thread.
*/ */
public void passivate() { public void passivate() {
if (!active) { if (!active) {
return; return;
} }
active = false; active = false;
} }
/** /**
* Main loop: sleep, generate event and publish. * Main loop: sleep, generate event and publish.
*/ */
public void run() { public void run() {
Log.debug(getClass().getName() + ": starting..."); Log.debug(getClass().getName() + ": starting...");
alive = true; alive = true;
while (alive) { while (alive) {
try { try {
Thread.sleep(getSleepTime()); Thread.sleep(getSleepTime());
// Stopped during sleep: end loop. // Stopped during sleep: end loop.
if (!alive) { if (!alive) {
break; break;
} }
// If passivated wait until we get // If passivated wait until we get
// get notify()-ied. If there are no subscribers // get notify()-ied. If there are no subscribers
// it wasts CPU to remain producing events... // it wasts CPU to remain producing events...
synchronized (this) { synchronized (this) {
while (!active) { while (!active) {
Log.debug(getClass().getName() + ": waiting..."); Log.debug(getClass().getName() + ": waiting...");
wait(); wait();
} }
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
break; break;
} }
try { try {
// Derived class should produce an event. // Derived class should produce an event.
Event event = pullEvent(); Event event = pullEvent();
// Let the publisher push it to subscribers. // Let the publisher push it to subscribers.
Dispatcher.getInstance().multicast(event); Dispatcher.getInstance().multicast(event);
} catch (Throwable t) { } catch (Throwable t) {
Log.warn("EventPullSource exception while multicasting ", t); Log.warn("EventPullSource exception while multicasting ", t);
t.printStackTrace(); t.printStackTrace();
} }
} }
Log.debug(getClass().getName() + ": stopped"); Log.debug(getClass().getName() + ": stopped");
} }
} }
/* /*
* $Log: EventPullSource.java,v $ * $Log: EventPullSource.java,v $
* Revision 1.15 2007/11/23 14:33:07 justb * Revision 1.15 2007/11/23 14:33:07 justb
* core classes now configurable through factory * core classes now configurable through factory
* *
* Revision 1.14 2005/02/28 09:14:55 justb * Revision 1.14 2005/02/28 09:14:55 justb
* sessmgr/dispatcher factory/singleton support * sessmgr/dispatcher factory/singleton support
* *
* Revision 1.13 2005/02/21 16:59:08 justb * Revision 1.13 2005/02/21 16:59:08 justb
* SessionManager and session lease introduced * SessionManager and session lease introduced
* *
* Revision 1.12 2005/02/21 11:50:46 justb * Revision 1.12 2005/02/21 11:50:46 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.11 2005/02/18 10:07:23 justb * Revision 1.11 2005/02/18 10:07:23 justb
* many renamings of classes (make names compact) * many renamings of classes (make names compact)
* *
* Revision 1.10 2005/02/18 09:54:15 justb * Revision 1.10 2005/02/18 09:54:15 justb
* refactor: rename Publisher Dispatcher and single Subscriber class * refactor: rename Publisher Dispatcher and single Subscriber class
* *
* Revision 1.9 2004/09/20 22:01:38 justb * Revision 1.9 2004/09/20 22:01:38 justb
* more changes for new protocol * more changes for new protocol
* *
* Revision 1.8 2004/09/03 22:35:37 justb * Revision 1.8 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.7 2004/08/15 16:00:15 justb * Revision 1.7 2004/08/15 16:00:15 justb
* enhancements to pull mode * enhancements to pull mode
* *
* Revision 1.6 2004/08/13 23:36:05 justb * Revision 1.6 2004/08/13 23:36:05 justb
* rewrite of Pullet into Pushlet "pull" mode * rewrite of Pullet into Pushlet "pull" mode
* *
* Revision 1.5 2004/03/10 14:01:55 justb * Revision 1.5 2004/03/10 14:01:55 justb
* formatting and *Subscriber refactoring * formatting and *Subscriber refactoring
* *
* Revision 1.4 2003/08/15 08:37:40 justb * Revision 1.4 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.3 2003/08/12 09:57:05 justb * Revision 1.3 2003/08/12 09:57:05 justb
* replaced all print statements to Log.*() calls * replaced all print statements to Log.*() calls
* *
* Revision 1.2 2003/05/18 16:15:08 justb * Revision 1.2 2003/05/18 16:15:08 justb
* support for XML encoded Events * support for XML encoded Events
* *
* Revision 1.1.1.1 2002/09/24 21:02:31 justb * Revision 1.1.1.1 2002/09/24 21:02:31 justb
* import to sourceforge * import to sourceforge
* *
* Revision 1.1.1.1 2002/09/20 22:48:17 justb * Revision 1.1.1.1 2002/09/20 22:48:17 justb
* import to SF * import to SF
* *
* Revision 1.1.1.1 2002/09/20 14:19:03 justb * Revision 1.1.1.1 2002/09/20 14:19:03 justb
* first import into SF * first import into SF
* *
* Revision 1.3 2002/04/15 20:42:41 just * Revision 1.3 2002/04/15 20:42:41 just
* reformatting and renaming GuardedQueue to EventQueue * reformatting and renaming GuardedQueue to EventQueue
* *
* Revision 1.2 2000/08/21 20:48:29 just * Revision 1.2 2000/08/21 20:48:29 just
* added CVS log and id tags plus copyrights * added CVS log and id tags plus copyrights
* *
* *
*/ */
@@ -1,79 +1,79 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.core; package nl.justobjects.pushlet.core;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
/** /**
* Abstract Event source from which Events are pulled. * Abstract Event source from which Events are pulled.
* *
* @version $Id: EventSource.java,v 1.7 2007/11/23 14:33:07 justb Exp $ * @version $Id: EventSource.java,v 1.7 2007/11/23 14:33:07 justb Exp $
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
**/ **/
/** /**
* Interface for specifc Event(Pull/Push)Sources. * Interface for specifc Event(Pull/Push)Sources.
*/ */
public interface EventSource { public interface EventSource {
/** /**
* Activate the event source. * Activate the event source.
*/ */
public void activate(); public void activate();
/** /**
* Deactivate the event source. * Deactivate the event source.
*/ */
public void passivate(); public void passivate();
/** /**
* Halt the event source. * Halt the event source.
*/ */
public void stop(); public void stop();
/** /**
* @author thomas genin * @author thomas genin
* gives access to the servlet context of pushlet to the source class * gives access to the servlet context of pushlet to the source class
*/ */
public void setServletContext(ServletContext srvCtxt); public void setServletContext(ServletContext srvCtxt);
} }
/* /*
* $Log: EventSource.java,v $ * $Log: EventSource.java,v $
* Revision 1.7 2007/11/23 14:33:07 justb * Revision 1.7 2007/11/23 14:33:07 justb
* core classes now configurable through factory * core classes now configurable through factory
* *
* Revision 1.6 2005/02/21 11:50:46 justb * Revision 1.6 2005/02/21 11:50:46 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.5 2005/02/18 10:07:23 justb * Revision 1.5 2005/02/18 10:07:23 justb
* many renamings of classes (make names compact) * many renamings of classes (make names compact)
* *
* Revision 1.4 2004/09/03 22:35:37 justb * Revision 1.4 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.3 2003/08/15 08:37:40 justb * Revision 1.3 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.2 2003/05/18 16:15:08 justb * Revision 1.2 2003/05/18 16:15:08 justb
* support for XML encoded Events * support for XML encoded Events
* *
* Revision 1.1.1.1 2002/09/24 21:02:31 justb * Revision 1.1.1.1 2002/09/24 21:02:31 justb
* import to sourceforge * import to sourceforge
* *
* Revision 1.1.1.1 2002/09/20 22:48:17 justb * Revision 1.1.1.1 2002/09/20 22:48:17 justb
* import to SF * import to SF
* *
* Revision 1.1.1.1 2002/09/20 14:19:03 justb * Revision 1.1.1.1 2002/09/20 14:19:03 justb
* first import into SF * first import into SF
* *
* Revision 1.3 2002/04/15 20:42:41 just * Revision 1.3 2002/04/15 20:42:41 just
* reformatting and renaming GuardedQueue to EventQueue * reformatting and renaming GuardedQueue to EventQueue
* *
* Revision 1.2 2000/08/21 20:48:29 just * Revision 1.2 2000/08/21 20:48:29 just
* added CVS log and id tags plus copyrights * added CVS log and id tags plus copyrights
* *
* *
*/ */
@@ -1,175 +1,175 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.core; package nl.justobjects.pushlet.core;
import nl.justobjects.pushlet.util.Log; import nl.justobjects.pushlet.util.Log;
import nl.justobjects.pushlet.util.Sys; import nl.justobjects.pushlet.util.Sys;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Properties; import java.util.Properties;
import java.util.Vector; import java.util.Vector;
import java.io.File; import java.io.File;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
/** /**
* Maintains lifecycle of event sources. * Maintains lifecycle of event sources.
* *
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
* @version $Id: EventSourceManager.java,v 1.14 2007/11/10 13:44:02 justb Exp $ * @version $Id: EventSourceManager.java,v 1.14 2007/11/10 13:44:02 justb Exp $
*/ */
public class EventSourceManager { public class EventSourceManager {
private static Vector eventSources = new Vector(0); private static Vector eventSources = new Vector(0);
private static final String PROPERTIES_FILE = "sources.properties"; private static final String PROPERTIES_FILE = "sources.properties";
/** /**
* Initialize event sources from properties file. * Initialize event sources from properties file.
*/ */
public static void start(String aDirPath,ServletContext srvCtxt) { public static void start(String aDirPath,ServletContext srvCtxt) {
// Load Event sources using properties file. // Load Event sources using properties file.
Log.info("EventSourceManager: start"); Log.info("EventSourceManager: start");
Properties properties = null; Properties properties = null;
try { try {
properties = Sys.loadPropertiesResource(PROPERTIES_FILE); properties = Sys.loadPropertiesResource(PROPERTIES_FILE);
} catch (Throwable t) { } catch (Throwable t) {
// Try from provided dir (e.g. WEB_INF/pushlet.properties) // Try from provided dir (e.g. WEB_INF/pushlet.properties)
String filePath = aDirPath + File.separator + PROPERTIES_FILE; String filePath = aDirPath + File.separator + PROPERTIES_FILE;
Log.info("EventSourceManager: cannot load " + PROPERTIES_FILE + " from classpath, will try from " + filePath); Log.info("EventSourceManager: cannot load " + PROPERTIES_FILE + " from classpath, will try from " + filePath);
try { try {
properties = Sys.loadPropertiesFile(filePath); properties = Sys.loadPropertiesFile(filePath);
} catch (Throwable t2) { } catch (Throwable t2) {
Log.fatal("EventSourceManager: cannot load properties file from " + filePath, t); Log.fatal("EventSourceManager: cannot load properties file from " + filePath, t);
// Give up // Give up
Log.warn("EventSourceManager: not starting local event sources (maybe that is what you want)"); Log.warn("EventSourceManager: not starting local event sources (maybe that is what you want)");
return; return;
} }
} }
// Create event source collection // Create event source collection
eventSources = new Vector(properties.size()); eventSources = new Vector(properties.size());
// Add the configured sources // Add the configured sources
for (Enumeration e = properties.keys(); e.hasMoreElements();) { for (Enumeration e = properties.keys(); e.hasMoreElements();) {
String nextKey = (String) e.nextElement(); String nextKey = (String) e.nextElement();
String nextClass = properties.getProperty(nextKey); String nextClass = properties.getProperty(nextKey);
EventSource nextEventSource = null; EventSource nextEventSource = null;
try { try {
nextEventSource = (EventSource) Class.forName(nextClass).newInstance(); nextEventSource = (EventSource) Class.forName(nextClass).newInstance();
//rajout thomas genin //rajout thomas genin
nextEventSource.setServletContext(srvCtxt); nextEventSource.setServletContext(srvCtxt);
////////////////////// //////////////////////
Log.info("created EventSource: key=" + nextKey + " class=" + nextClass); Log.info("created EventSource: key=" + nextKey + " class=" + nextClass);
eventSources.addElement(nextEventSource); eventSources.addElement(nextEventSource);
} catch (Exception ex) { } catch (Exception ex) {
Log.warn("Cannot create EventSource: class=" + nextClass, ex); Log.warn("Cannot create EventSource: class=" + nextClass, ex);
} }
} }
activate(); activate();
} }
/** /**
* Activate all event sources. * Activate all event sources.
*/ */
public static void activate() { public static void activate() {
Log.info("Activating " + eventSources.size() + " EventSources"); Log.info("Activating " + eventSources.size() + " EventSources");
for (int i = 0; i < eventSources.size(); i++) { for (int i = 0; i < eventSources.size(); i++) {
((EventSource) eventSources.elementAt(i)).activate(); ((EventSource) eventSources.elementAt(i)).activate();
} }
Log.info("EventSources activated"); Log.info("EventSources activated");
} }
/** /**
* Deactivate all event sources. * Deactivate all event sources.
*/ */
public static void passivate() { public static void passivate() {
Log.info("Passivating " + eventSources.size() + " EventSources"); Log.info("Passivating " + eventSources.size() + " EventSources");
for (int i = 0; i < eventSources.size(); i++) { for (int i = 0; i < eventSources.size(); i++) {
((EventSource) eventSources.elementAt(i)).passivate(); ((EventSource) eventSources.elementAt(i)).passivate();
} }
Log.info("EventSources passivated"); Log.info("EventSources passivated");
} }
/** /**
* Halt event sources. * Halt event sources.
*/ */
public static void stop() { public static void stop() {
Log.info("Stopping " + eventSources.size() + " EventSources..."); Log.info("Stopping " + eventSources.size() + " EventSources...");
for (int i = 0; i < eventSources.size(); i++) { for (int i = 0; i < eventSources.size(); i++) {
((EventSource) eventSources.elementAt(i)).stop(); ((EventSource) eventSources.elementAt(i)).stop();
} }
Log.info("EventSources stopped"); Log.info("EventSources stopped");
} }
} }
/* /*
* $Log: EventSourceManager.java,v $ * $Log: EventSourceManager.java,v $
* Revision 1.14 2007/11/10 13:44:02 justb * Revision 1.14 2007/11/10 13:44:02 justb
* pushlet.properties and sources.properties can now also be put under WEB-INF * pushlet.properties and sources.properties can now also be put under WEB-INF
* *
* Revision 1.13 2005/02/21 11:50:46 justb * Revision 1.13 2005/02/21 11:50:46 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.12 2005/02/18 12:36:47 justb * Revision 1.12 2005/02/18 12:36:47 justb
* changes for renaming and configurability * changes for renaming and configurability
* *
* Revision 1.11 2005/02/18 10:07:23 justb * Revision 1.11 2005/02/18 10:07:23 justb
* many renamings of classes (make names compact) * many renamings of classes (make names compact)
* *
* Revision 1.10 2005/02/15 13:29:49 justb * Revision 1.10 2005/02/15 13:29:49 justb
* use Sys.loadPropertiesResource() * use Sys.loadPropertiesResource()
* *
* Revision 1.9 2004/09/20 22:01:38 justb * Revision 1.9 2004/09/20 22:01:38 justb
* more changes for new protocol * more changes for new protocol
* *
* Revision 1.8 2004/09/03 22:35:37 justb * Revision 1.8 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.7 2004/08/15 16:00:15 justb * Revision 1.7 2004/08/15 16:00:15 justb
* enhancements to pull mode * enhancements to pull mode
* *
* Revision 1.6 2004/08/13 23:36:05 justb * Revision 1.6 2004/08/13 23:36:05 justb
* rewrite of Pullet into Pushlet "pull" mode * rewrite of Pullet into Pushlet "pull" mode
* *
* Revision 1.5 2004/08/12 13:18:54 justb * Revision 1.5 2004/08/12 13:18:54 justb
* cosmetic changes * cosmetic changes
* *
* Revision 1.4 2003/08/15 08:37:40 justb * Revision 1.4 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.3 2003/08/12 09:41:35 justb * Revision 1.3 2003/08/12 09:41:35 justb
* replace static initalizer with explicit init() * replace static initalizer with explicit init()
* *
* Revision 1.2 2003/05/18 16:15:08 justb * Revision 1.2 2003/05/18 16:15:08 justb
* support for XML encoded Events * support for XML encoded Events
* *
* Revision 1.1.1.1 2002/09/24 21:02:31 justb * Revision 1.1.1.1 2002/09/24 21:02:31 justb
* import to sourceforge * import to sourceforge
* *
* Revision 1.1.1.1 2002/09/20 22:48:17 justb * Revision 1.1.1.1 2002/09/20 22:48:17 justb
* import to SF * import to SF
* *
* Revision 1.1.1.1 2002/09/20 14:19:03 justb * Revision 1.1.1.1 2002/09/20 14:19:03 justb
* first import into SF * first import into SF
* *
* Revision 1.5 2002/04/15 20:42:41 just * Revision 1.5 2002/04/15 20:42:41 just
* reformatting and renaming GuardedQueue to EventQueue * reformatting and renaming GuardedQueue to EventQueue
* *
* Revision 1.4 2000/10/30 14:15:47 just * Revision 1.4 2000/10/30 14:15:47 just
* no message * no message
* *
* Revision 1.3 2000/08/31 08:26:54 just * Revision 1.3 2000/08/31 08:26:54 just
* Changed classloader that loads eventsources.properties to use EventSourceManager's classloader * Changed classloader that loads eventsources.properties to use EventSourceManager's classloader
* *
* Revision 1.2 2000/08/21 20:48:29 just * Revision 1.2 2000/08/21 20:48:29 just
* added CVS log and id tags plus copyrights * added CVS log and id tags plus copyrights
* *
* *
*/ */
@@ -1,99 +1,99 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.core; package nl.justobjects.pushlet.core;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
/** /**
* Implementation of ClientAdapter that sends Events as serialized objects. * Implementation of ClientAdapter that sends Events as serialized objects.
* <p/> * <p/>
* NOTE: You are discouraged to use this adapter, since it is Java-only * NOTE: You are discouraged to use this adapter, since it is Java-only
* and may have JVM-specific problems. Far better choice is to use XML * and may have JVM-specific problems. Far better choice is to use XML
* and the XMLAdapter. * and the XMLAdapter.
* *
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
* @version $Id: SerializedAdapter.java,v 1.4 2007/11/23 14:33:07 justb Exp $ * @version $Id: SerializedAdapter.java,v 1.4 2007/11/23 14:33:07 justb Exp $
*/ */
class SerializedAdapter implements ClientAdapter { class SerializedAdapter implements ClientAdapter {
private ObjectOutputStream out = null; private ObjectOutputStream out = null;
public static final String CONTENT_TYPE = "application/x-java-serialized-object"; public static final String CONTENT_TYPE = "application/x-java-serialized-object";
private HttpServletResponse servletRsp; private HttpServletResponse servletRsp;
/** /**
* Initialize. * Initialize.
*/ */
public SerializedAdapter(HttpServletResponse aServletResponse) { public SerializedAdapter(HttpServletResponse aServletResponse) {
servletRsp = aServletResponse; servletRsp = aServletResponse;
} }
public void start() throws IOException { public void start() throws IOException {
servletRsp.setContentType(CONTENT_TYPE); servletRsp.setContentType(CONTENT_TYPE);
// Use a serialized object output stream // Use a serialized object output stream
out = new ObjectOutputStream(servletRsp.getOutputStream()); out = new ObjectOutputStream(servletRsp.getOutputStream());
// Don't need this further // Don't need this further
servletRsp = null; servletRsp = null;
} }
/** /**
* Push Event to client. * Push Event to client.
*/ */
public void push(Event anEvent) throws IOException { public void push(Event anEvent) throws IOException {
out.writeObject(anEvent); out.writeObject(anEvent);
out.flush(); out.flush();
} }
public void stop() throws IOException { public void stop() throws IOException {
} }
} }
/* /*
* $Log: SerializedAdapter.java,v $ * $Log: SerializedAdapter.java,v $
* Revision 1.4 2007/11/23 14:33:07 justb * Revision 1.4 2007/11/23 14:33:07 justb
* core classes now configurable through factory * core classes now configurable through factory
* *
* Revision 1.3 2005/02/28 12:45:59 justb * Revision 1.3 2005/02/28 12:45:59 justb
* introduced Command class * introduced Command class
* *
* Revision 1.2 2005/02/21 11:50:46 justb * Revision 1.2 2005/02/21 11:50:46 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.1 2005/02/18 10:07:23 justb * Revision 1.1 2005/02/18 10:07:23 justb
* many renamings of classes (make names compact) * many renamings of classes (make names compact)
* *
* Revision 1.4 2004/09/03 22:35:37 justb * Revision 1.4 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.3 2003/08/15 08:37:40 justb * Revision 1.3 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.2 2003/05/18 16:13:48 justb * Revision 1.2 2003/05/18 16:13:48 justb
* fixed blocking for java.net.URL with HTTP/1.1 (JVMs > 1.1) * fixed blocking for java.net.URL with HTTP/1.1 (JVMs > 1.1)
* *
* Revision 1.1.1.1 2002/09/24 21:02:31 justb * Revision 1.1.1.1 2002/09/24 21:02:31 justb
* import to sourceforge * import to sourceforge
* *
* Revision 1.1.1.1 2002/09/20 22:48:18 justb * Revision 1.1.1.1 2002/09/20 22:48:18 justb
* import to SF * import to SF
* *
* Revision 1.1.1.1 2002/09/20 14:19:03 justb * Revision 1.1.1.1 2002/09/20 14:19:03 justb
* first import into SF * first import into SF
* *
* Revision 1.5 2002/04/15 20:42:41 just * Revision 1.5 2002/04/15 20:42:41 just
* reformatting and renaming GuardedQueue to EventQueue * reformatting and renaming GuardedQueue to EventQueue
* *
* Revision 1.4 2000/12/27 22:39:35 just * Revision 1.4 2000/12/27 22:39:35 just
* no message * no message
* *
* Revision 1.3 2000/08/21 20:48:29 just * Revision 1.3 2000/08/21 20:48:29 just
* added CVS log and id tags plus copyrights * added CVS log and id tags plus copyrights
* *
* *
*/ */
@@ -1,137 +1,137 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.core; package nl.justobjects.pushlet.core;
import nl.justobjects.pushlet.util.Log; import nl.justobjects.pushlet.util.Log;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
/** /**
* ClientAdapter that sends Events as XML. * ClientAdapter that sends Events as XML.
* *
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
* @version $Id: XMLAdapter.java,v 1.7 2007/11/09 13:15:35 justb Exp $ * @version $Id: XMLAdapter.java,v 1.7 2007/11/09 13:15:35 justb Exp $
*/ */
class XMLAdapter implements ClientAdapter { class XMLAdapter implements ClientAdapter {
/** /**
* Header for strict XML * Header for strict XML
*/ */
// public static final String XML_HEAD = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"; // public static final String XML_HEAD = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
private String contentType = "text/plain;charset=UTF-8"; private String contentType = "text/plain;charset=UTF-8";
private ServletOutputStream out = null; private ServletOutputStream out = null;
private HttpServletResponse servletRsp; private HttpServletResponse servletRsp;
private boolean strictXML; private boolean strictXML;
/** /**
* Initialize. * Initialize.
*/ */
public XMLAdapter(HttpServletResponse aServletResponse) { public XMLAdapter(HttpServletResponse aServletResponse) {
this(aServletResponse, false); this(aServletResponse, false);
} }
/** /**
* Initialize. * Initialize.
*/ */
public XMLAdapter(HttpServletResponse aServletResponse, boolean useStrictXML) { public XMLAdapter(HttpServletResponse aServletResponse, boolean useStrictXML) {
servletRsp = aServletResponse; servletRsp = aServletResponse;
// Strict XML implies returning a complete XML document // Strict XML implies returning a complete XML document
strictXML = useStrictXML; strictXML = useStrictXML;
if (strictXML) { if (strictXML) {
contentType = "text/xml;charset=UTF-8"; contentType = "text/xml;charset=UTF-8";
} }
} }
public void start() throws IOException { public void start() throws IOException {
// If content type is plain text // If content type is plain text
// then this is not a complete XML document, but rather // then this is not a complete XML document, but rather
// a stream of XML documents where each document is // a stream of XML documents where each document is
// an Event. In strict XML mode a complete document is returned. // an Event. In strict XML mode a complete document is returned.
servletRsp.setContentType(contentType); servletRsp.setContentType(contentType);
out = servletRsp.getOutputStream(); out = servletRsp.getOutputStream();
// Don't need this further // Don't need this further
servletRsp = null; servletRsp = null;
// Start XML document if strict XML mode // Start XML document if strict XML mode
if (strictXML) { if (strictXML) {
out.print("<pushlet>"); out.print("<pushlet>");
} }
} }
/** /**
* Force client to refresh the request. * Force client to refresh the request.
*/ */
public void push(Event anEvent) throws IOException { public void push(Event anEvent) throws IOException {
debug("event=" + anEvent); debug("event=" + anEvent);
// Send the event as XML to the client and flush. // Send the event as XML to the client and flush.
out.print(anEvent.toXML(strictXML)); out.print(anEvent.toXML(strictXML));
out.flush(); out.flush();
} }
/** /**
* No action. * No action.
*/ */
public void stop() throws IOException { public void stop() throws IOException {
// Close XML document if strict XML mode // Close XML document if strict XML mode
if (strictXML) { if (strictXML) {
out.print("</pushlet>"); out.print("</pushlet>");
out.flush(); out.flush();
} }
} }
private void debug(String s) { private void debug(String s) {
Log.debug("[XMLAdapter]" + s); Log.debug("[XMLAdapter]" + s);
} }
} }
/* /*
* $Log: XMLAdapter.java,v $ * $Log: XMLAdapter.java,v $
* Revision 1.7 2007/11/09 13:15:35 justb * Revision 1.7 2007/11/09 13:15:35 justb
* add charset=UTF-8 in returned HTTP content types * add charset=UTF-8 in returned HTTP content types
* *
* Revision 1.6 2006/05/15 11:52:53 justb * Revision 1.6 2006/05/15 11:52:53 justb
* updates mainly for AJAX client * updates mainly for AJAX client
* *
* Revision 1.5 2006/05/06 00:06:28 justb * Revision 1.5 2006/05/06 00:06:28 justb
* first rough version AJAX client * first rough version AJAX client
* *
* Revision 1.4 2005/05/06 19:44:00 justb * Revision 1.4 2005/05/06 19:44:00 justb
* added xml-strict format * added xml-strict format
* *
* Revision 1.3 2005/02/28 12:45:59 justb * Revision 1.3 2005/02/28 12:45:59 justb
* introduced Command class * introduced Command class
* *
* Revision 1.2 2005/02/21 11:50:47 justb * Revision 1.2 2005/02/21 11:50:47 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.1 2005/02/18 10:07:23 justb * Revision 1.1 2005/02/18 10:07:23 justb
* many renamings of classes (make names compact) * many renamings of classes (make names compact)
* *
* Revision 1.7 2004/09/03 22:35:37 justb * Revision 1.7 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.6 2004/03/10 14:01:55 justb * Revision 1.6 2004/03/10 14:01:55 justb
* formatting and *Subscriber refactoring * formatting and *Subscriber refactoring
* *
* Revision 1.5 2003/08/15 08:37:40 justb * Revision 1.5 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.4 2003/08/13 14:00:00 justb * Revision 1.4 2003/08/13 14:00:00 justb
* some testing for applets; no real change * some testing for applets; no real change
* *
* Revision 1.3 2003/08/12 09:57:06 justb * Revision 1.3 2003/08/12 09:57:06 justb
* replaced all print statements to Log.*() calls * replaced all print statements to Log.*() calls
* *
* Revision 1.2 2003/05/19 21:56:29 justb * Revision 1.2 2003/05/19 21:56:29 justb
* various fixes for applet clients * various fixes for applet clients
* *
* Revision 1.1 2003/05/18 16:12:28 justb * Revision 1.1 2003/05/18 16:12:28 justb
* adding support for XML encoded Events * adding support for XML encoded Events
*/ */
@@ -1,164 +1,164 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.util; package nl.justobjects.pushlet.util;
/** /**
* Default logger. * Default logger.
* <p/> * <p/>
* Logs to stdout. Override this class by setting "logger.class" in pushlet.properties to your own logger * Logs to stdout. Override this class by setting "logger.class" in pushlet.properties to your own logger
* to integrate your own logging library. * to integrate your own logging library.
* *
* @author Just van den Broecke * @author Just van den Broecke
* @version $Id: DefaultLogger.java,v 1.2 2007/12/07 12:57:40 justb Exp $ * @version $Id: DefaultLogger.java,v 1.2 2007/12/07 12:57:40 justb Exp $
*/ */
public class DefaultLogger implements PushletLogger { public class DefaultLogger implements PushletLogger {
/** /**
* Level intialized with default. * Level intialized with default.
*/ */
private int level = LOG_LEVEL_INFO; private int level = LOG_LEVEL_INFO;
public DefaultLogger() { public DefaultLogger() {
} }
public void init() { public void init() {
} }
/** /**
* Log message for trace level. * Log message for trace level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
public void trace(String aMessage) { public void trace(String aMessage) {
if (level < LOG_LEVEL_TRACE) { if (level < LOG_LEVEL_TRACE) {
return; return;
} }
print("TRACE", aMessage); print("TRACE", aMessage);
} }
/** /**
* Log message for debug level. * Log message for debug level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
public void debug(String aMessage) { public void debug(String aMessage) {
if (level < LOG_LEVEL_DEBUG) { if (level < LOG_LEVEL_DEBUG) {
return; return;
} }
print("DEBUG", aMessage); print("DEBUG", aMessage);
} }
/** /**
* Log message for info level. * Log message for info level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
public void info(String aMessage) { public void info(String aMessage) {
if (level < LOG_LEVEL_INFO) { if (level < LOG_LEVEL_INFO) {
return; return;
} }
print("INFO", aMessage); print("INFO", aMessage);
} }
/** /**
* Log message for warning level. * Log message for warning level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
public void warn(String aMessage) { public void warn(String aMessage) {
if (level < LOG_LEVEL_WARN) { if (level < LOG_LEVEL_WARN) {
return; return;
} }
print("WARN", aMessage); print("WARN", aMessage);
} }
/** /**
* Log message for warning level with exception. * Log message for warning level with exception.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
* @param aThrowable the exception * @param aThrowable the exception
*/ */
public void warn(String aMessage, Throwable aThrowable) { public void warn(String aMessage, Throwable aThrowable) {
warn(aMessage + " exception=" + aThrowable); warn(aMessage + " exception=" + aThrowable);
} }
/** /**
* Log message for error level. * Log message for error level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
public void error(String aMessage) { public void error(String aMessage) {
if (level < LOG_LEVEL_ERROR) { if (level < LOG_LEVEL_ERROR) {
return; return;
} }
print("FATAL", aMessage); print("FATAL", aMessage);
} }
/** /**
* Log message (error level with exception). * Log message (error level with exception).
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
* @param aThrowable the exception * @param aThrowable the exception
*/ */
public void error(String aMessage, Throwable aThrowable) { public void error(String aMessage, Throwable aThrowable) {
error(aMessage + " exception=" + aThrowable); error(aMessage + " exception=" + aThrowable);
} }
/** /**
* Log message for fatal level. * Log message for fatal level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
public void fatal(String aMessage) { public void fatal(String aMessage) {
if (level < LOG_LEVEL_FATAL) { if (level < LOG_LEVEL_FATAL) {
return; return;
} }
print("FATAL", aMessage); print("FATAL", aMessage);
} }
/** /**
* Log message (fatal level with exception). * Log message (fatal level with exception).
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
* @param aThrowable the exception * @param aThrowable the exception
*/ */
public void fatal(String aMessage, Throwable aThrowable) { public void fatal(String aMessage, Throwable aThrowable) {
fatal(aMessage + " exception=" + aThrowable); fatal(aMessage + " exception=" + aThrowable);
} }
/** /**
* Set log level * Set log level
* *
* @param aLevel the message to be logged * @param aLevel the message to be logged
*/ */
public void setLevel(int aLevel) { public void setLevel(int aLevel) {
level = aLevel; level = aLevel;
} }
/** /**
* Print message. * Print message.
* *
* @param aTag the log type * @param aTag the log type
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
private void print(String aTag, String aMessage) { private void print(String aTag, String aMessage) {
// SImple std out e.g. to catalina.out in Tomcat // SImple std out e.g. to catalina.out in Tomcat
System.out.println("Pushlet[" + aTag + "] " + aMessage); System.out.println("Pushlet[" + aTag + "] " + aMessage);
} }
} }
/* /*
* $Log: DefaultLogger.java,v $ * $Log: DefaultLogger.java,v $
* Revision 1.2 2007/12/07 12:57:40 justb * Revision 1.2 2007/12/07 12:57:40 justb
* added log4j and make it the default logging method * added log4j and make it the default logging method
* *
* Revision 1.1 2007/11/23 21:10:17 justb * Revision 1.1 2007/11/23 21:10:17 justb
* add hooks for custom logging (you can override DefaultLogger in pushlet.properties) * add hooks for custom logging (you can override DefaultLogger in pushlet.properties)
* *
* *
* *
*/ */
@@ -1,178 +1,178 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.util; package nl.justobjects.pushlet.util;
import nl.justobjects.pushlet.core.Config; import nl.justobjects.pushlet.core.Config;
import nl.justobjects.pushlet.core.ConfigDefs; import nl.justobjects.pushlet.core.ConfigDefs;
/** /**
* Logging wrapper. * Logging wrapper.
* <p/> * <p/>
* Provides a hook to direct logging to your own logging library. Override the DefaultLogger class by setting * Provides a hook to direct logging to your own logging library. Override the DefaultLogger class by setting
* "logger.class" in pushlet.properties to your own logger * "logger.class" in pushlet.properties to your own logger
* to integrate your own logging library. * to integrate your own logging library.
* *
* @author Just van den Broecke * @author Just van den Broecke
* @version $Id: Log.java,v 1.5 2007/12/07 12:57:40 justb Exp $ * @version $Id: Log.java,v 1.5 2007/12/07 12:57:40 justb Exp $
*/ */
public class Log implements ConfigDefs { public class Log implements ConfigDefs {
/** /**
* Init with default to have at least some logging. * Init with default to have at least some logging.
*/ */
private static PushletLogger logger = new DefaultLogger(); private static PushletLogger logger = new DefaultLogger();
/** /**
* General purpose initialization. * General purpose initialization.
*/ */
static public void init() { static public void init() {
try { try {
logger = (PushletLogger) Config.getClass(LOGGER_CLASS, "nl.justobjects.pushlet.util.DefaultLogger").newInstance(); logger = (PushletLogger) Config.getClass(LOGGER_CLASS, "nl.justobjects.pushlet.util.DefaultLogger").newInstance();
} catch (Throwable t) { } catch (Throwable t) {
// Hmmm cannot log this since we don't have a log... // Hmmm cannot log this since we don't have a log...
System.out.println("Cannot instantiate Logger from config ex=" + t); System.out.println("Cannot instantiate Logger from config ex=" + t);
return; return;
} }
logger.init(); logger.init();
// Set log level // Set log level
logger.setLevel(Config.getIntProperty(Config.LOG_LEVEL)); logger.setLevel(Config.getIntProperty(Config.LOG_LEVEL));
logger.info("Logging intialized logger class=" + logger.getClass()); logger.info("Logging intialized logger class=" + logger.getClass());
} }
/** /**
* Log message for trace level. * Log message for trace level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
static public void trace(String aMessage) { static public void trace(String aMessage) {
logger.debug(aMessage); logger.debug(aMessage);
} }
/** /**
* Log message for debug level. * Log message for debug level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
static public void debug(String aMessage) { static public void debug(String aMessage) {
logger.debug(aMessage); logger.debug(aMessage);
} }
/** /**
* Log message for info level. * Log message for info level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
static public void info(String aMessage) { static public void info(String aMessage) {
logger.info(aMessage); logger.info(aMessage);
} }
/** /**
* Log message for warning level. * Log message for warning level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
static public void warn(String aMessage) { static public void warn(String aMessage) {
logger.warn(aMessage); logger.warn(aMessage);
} }
/** /**
* Log message for warning level with exception. * Log message for warning level with exception.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
* @param aThrowable the exception * @param aThrowable the exception
*/ */
static public void warn(String aMessage, Throwable aThrowable) { static public void warn(String aMessage, Throwable aThrowable) {
logger.warn(aMessage, aThrowable); logger.warn(aMessage, aThrowable);
} }
/** /**
* Log message for error level. * Log message for error level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
static public void error(String aMessage) { static public void error(String aMessage) {
logger.error(aMessage); logger.error(aMessage);
} }
/** /**
* Log message (error level with exception). * Log message (error level with exception).
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
* @param aThrowable the exception * @param aThrowable the exception
*/ */
static public void error(String aMessage, Throwable aThrowable) { static public void error(String aMessage, Throwable aThrowable) {
logger.error(aMessage, aThrowable); logger.error(aMessage, aThrowable);
} }
/** /**
* Log message for fatal level. * Log message for fatal level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
static public void fatal(String aMessage) { static public void fatal(String aMessage) {
logger.fatal(aMessage); logger.fatal(aMessage);
} }
/** /**
* Log message (fatal level with exception). * Log message (fatal level with exception).
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
* @param aThrowable the exception * @param aThrowable the exception
*/ */
static public void fatal(String aMessage, Throwable aThrowable) { static public void fatal(String aMessage, Throwable aThrowable) {
logger.fatal(aMessage, aThrowable); logger.fatal(aMessage, aThrowable);
} }
/** /**
* Set log level * Set log level
* *
* @param aLevel the message to be logged * @param aLevel the message to be logged
*/ */
static public void setLevel(int aLevel) { static public void setLevel(int aLevel) {
logger.setLevel(aLevel); logger.setLevel(aLevel);
} }
} }
/* /*
* $Log: Log.java,v $ * $Log: Log.java,v $
* Revision 1.5 2007/12/07 12:57:40 justb * Revision 1.5 2007/12/07 12:57:40 justb
* added log4j and make it the default logging method * added log4j and make it the default logging method
* *
* Revision 1.4 2007/11/23 21:29:43 justb * Revision 1.4 2007/11/23 21:29:43 justb
* add hooks for custom logging (you can override DefaultLogger in pushlet.properties) * add hooks for custom logging (you can override DefaultLogger in pushlet.properties)
* *
* Revision 1.3 2007/11/23 21:10:17 justb * Revision 1.3 2007/11/23 21:10:17 justb
* add hooks for custom logging (you can override DefaultLogger in pushlet.properties) * add hooks for custom logging (you can override DefaultLogger in pushlet.properties)
* *
* Revision 1.2 2005/02/21 11:15:59 justb * Revision 1.2 2005/02/21 11:15:59 justb
* support log levels * support log levels
* *
* Revision 1.1 2005/02/18 10:07:23 justb * Revision 1.1 2005/02/18 10:07:23 justb
* many renamings of classes (make names compact) * many renamings of classes (make names compact)
* *
* Revision 1.7 2004/09/03 22:35:37 justb * Revision 1.7 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.6 2004/08/12 13:16:08 justb * Revision 1.6 2004/08/12 13:16:08 justb
* make debug flag false * make debug flag false
* *
* Revision 1.5 2004/03/10 14:01:55 justb * Revision 1.5 2004/03/10 14:01:55 justb
* formatting and *Subscriber refactoring * formatting and *Subscriber refactoring
* *
* Revision 1.4 2003/08/15 09:54:46 justb * Revision 1.4 2003/08/15 09:54:46 justb
* fix javadoc warnings * fix javadoc warnings
* *
* Revision 1.3 2003/08/15 08:37:40 justb * Revision 1.3 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.2 2003/08/12 09:42:47 justb * Revision 1.2 2003/08/12 09:42:47 justb
* enhancements * enhancements
* *
* Revision 1.1 2003/08/12 08:46:00 justb * Revision 1.1 2003/08/12 08:46:00 justb
* cvs comment tags added * cvs comment tags added
* *
* *
*/ */
@@ -1,134 +1,134 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.util; package nl.justobjects.pushlet.util;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import org.apache.log4j.LogManager; import org.apache.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
* Logger to use Log4j for logging. * Logger to use Log4j for logging.
* <p/> * <p/>
* Logs using Log4j. * Logs using Log4j.
* This class will require a log4j library in the classpath of the Pushlet. * This class will require a log4j library in the classpath of the Pushlet.
* *
* @author Uli Romahn * @author Uli Romahn
* @version $Id: Log4jLogger.java,v 1.1 2007/12/07 12:57:40 justb Exp $ * @version $Id: Log4jLogger.java,v 1.1 2007/12/07 12:57:40 justb Exp $
*/ */
public class Log4jLogger implements PushletLogger { public class Log4jLogger implements PushletLogger {
/** /**
* Level intialized with default. * Level intialized with default.
*/ */
private Logger logger = LogManager.getLogger("pushlet"); private Logger logger = LogManager.getLogger("pushlet");
/* (non-Javadoc) /* (non-Javadoc)
* @see nl.justobjects.pushlet.util.PushletLogger#init() * @see nl.justobjects.pushlet.util.PushletLogger#init()
*/ */
public void init() { public void init() {
setLevel(LOG_LEVEL_INFO); setLevel(LOG_LEVEL_INFO);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see nl.justobjects.pushlet.util.PushletLogger#debug(java.lang.String) * @see nl.justobjects.pushlet.util.PushletLogger#debug(java.lang.String)
*/ */
public void debug(String aMessage) { public void debug(String aMessage) {
if (!logger.isDebugEnabled()) { if (!logger.isDebugEnabled()) {
return; return;
} }
logger.debug(aMessage); logger.debug(aMessage);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see nl.justobjects.pushlet.util.PushletLogger#error(java.lang.String) * @see nl.justobjects.pushlet.util.PushletLogger#error(java.lang.String)
*/ */
public void error(String aMessage) { public void error(String aMessage) {
logger.error(aMessage); logger.error(aMessage);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see nl.justobjects.pushlet.util.PushletLogger#error(java.lang.String, java.lang.Throwable) * @see nl.justobjects.pushlet.util.PushletLogger#error(java.lang.String, java.lang.Throwable)
*/ */
public void error(String aMessage, Throwable aThrowable) { public void error(String aMessage, Throwable aThrowable) {
logger.error(aMessage, aThrowable); logger.error(aMessage, aThrowable);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see nl.justobjects.pushlet.util.PushletLogger#fatal(java.lang.String) * @see nl.justobjects.pushlet.util.PushletLogger#fatal(java.lang.String)
*/ */
public void fatal(String aMessage) { public void fatal(String aMessage) {
logger.fatal(aMessage); logger.fatal(aMessage);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see nl.justobjects.pushlet.util.PushletLogger#fatal(java.lang.String, java.lang.Throwable) * @see nl.justobjects.pushlet.util.PushletLogger#fatal(java.lang.String, java.lang.Throwable)
*/ */
public void fatal(String aMessage, Throwable aThrowable) { public void fatal(String aMessage, Throwable aThrowable) {
logger.fatal(aMessage, aThrowable); logger.fatal(aMessage, aThrowable);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see nl.justobjects.pushlet.util.PushletLogger#info(java.lang.String) * @see nl.justobjects.pushlet.util.PushletLogger#info(java.lang.String)
*/ */
public void info(String aMessage) { public void info(String aMessage) {
if (!logger.isInfoEnabled()) { if (!logger.isInfoEnabled()) {
return; return;
} }
logger.info(aMessage); logger.info(aMessage);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see nl.justobjects.pushlet.util.PushletLogger#trace(java.lang.String) * @see nl.justobjects.pushlet.util.PushletLogger#trace(java.lang.String)
*/ */
public void trace(String aMessage) { public void trace(String aMessage) {
logger.trace(aMessage); logger.trace(aMessage);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see nl.justobjects.pushlet.util.PushletLogger#warn(java.lang.String) * @see nl.justobjects.pushlet.util.PushletLogger#warn(java.lang.String)
*/ */
public void warn(String aMessage) { public void warn(String aMessage) {
logger.warn(aMessage); logger.warn(aMessage);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see nl.justobjects.pushlet.util.PushletLogger#warn(java.lang.String, java.lang.Throwable) * @see nl.justobjects.pushlet.util.PushletLogger#warn(java.lang.String, java.lang.Throwable)
*/ */
public void warn(String aMessage, Throwable aThrowable) { public void warn(String aMessage, Throwable aThrowable) {
logger.warn(aMessage, aThrowable); logger.warn(aMessage, aThrowable);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see nl.justobjects.pushlet.util.PushletLogger#setLevel(int) * @see nl.justobjects.pushlet.util.PushletLogger#setLevel(int)
*/ */
public void setLevel(int aLevel) { public void setLevel(int aLevel) {
if (aLevel < LOG_LEVEL_FATAL) { if (aLevel < LOG_LEVEL_FATAL) {
logger.setLevel(Level.OFF); logger.setLevel(Level.OFF);
} else { } else {
switch (aLevel) { switch (aLevel) {
case LOG_LEVEL_FATAL: case LOG_LEVEL_FATAL:
logger.setLevel(Level.FATAL); logger.setLevel(Level.FATAL);
break; break;
case LOG_LEVEL_ERROR: case LOG_LEVEL_ERROR:
logger.setLevel(Level.ERROR); logger.setLevel(Level.ERROR);
break; break;
case LOG_LEVEL_WARN: case LOG_LEVEL_WARN:
logger.setLevel(Level.WARN); logger.setLevel(Level.WARN);
break; break;
case LOG_LEVEL_INFO: case LOG_LEVEL_INFO:
logger.setLevel(Level.INFO); logger.setLevel(Level.INFO);
break; break;
case LOG_LEVEL_DEBUG: case LOG_LEVEL_DEBUG:
logger.setLevel(Level.DEBUG); logger.setLevel(Level.DEBUG);
break; break;
case LOG_LEVEL_TRACE: case LOG_LEVEL_TRACE:
logger.setLevel(Level.TRACE); logger.setLevel(Level.TRACE);
break; break;
default: default:
logger.setLevel(Level.INFO); logger.setLevel(Level.INFO);
} }
} }
} }
} }
@@ -1,94 +1,94 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.util; package nl.justobjects.pushlet.util;
import nl.justobjects.pushlet.core.ConfigDefs; import nl.justobjects.pushlet.core.ConfigDefs;
/** /**
* Logger interface to allow different logging providers. * Logger interface to allow different logging providers.
* <p/> * <p/>
* *
* @author Ulrich Romahn * @author Ulrich Romahn
* @version $Id: PushletLogger.java,v 1.1 2007/12/07 12:57:40 justb Exp $ * @version $Id: PushletLogger.java,v 1.1 2007/12/07 12:57:40 justb Exp $
*/ */
public interface PushletLogger extends ConfigDefs { public interface PushletLogger extends ConfigDefs {
/** /**
* Method allowing to initialize our logger * Method allowing to initialize our logger
*/ */
public void init(); public void init();
/** /**
* Log message for trace level. * Log message for trace level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
public void trace(String aMessage); public void trace(String aMessage);
/** /**
* Log message for debug level. * Log message for debug level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
public void debug(String aMessage); public void debug(String aMessage);
/** /**
* Log message for info level. * Log message for info level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
public void info(String aMessage); public void info(String aMessage);
/** /**
* Log message for warning level. * Log message for warning level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
public void warn(String aMessage); public void warn(String aMessage);
/** /**
* Log message for warning level with exception. * Log message for warning level with exception.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
* @param aThrowable the exception * @param aThrowable the exception
*/ */
public void warn(String aMessage, Throwable aThrowable); public void warn(String aMessage, Throwable aThrowable);
/** /**
* Log message for error level. * Log message for error level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
public void error(String aMessage); public void error(String aMessage);
/** /**
* Log message (error level with exception). * Log message (error level with exception).
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
* @param aThrowable the exception * @param aThrowable the exception
*/ */
public void error(String aMessage, Throwable aThrowable); public void error(String aMessage, Throwable aThrowable);
/** /**
* Log message for fatal level. * Log message for fatal level.
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
*/ */
public void fatal(String aMessage); public void fatal(String aMessage);
/** /**
* Log message (fatal level with exception). * Log message (fatal level with exception).
* *
* @param aMessage the message to be logged * @param aMessage the message to be logged
* @param aThrowable the exception * @param aThrowable the exception
*/ */
public void fatal(String aMessage, Throwable aThrowable); public void fatal(String aMessage, Throwable aThrowable);
/** /**
* Set log level * Set log level
* *
* @param aLevel a valid Level from ConfigDefs * @param aLevel a valid Level from ConfigDefs
*/ */
public void setLevel(int aLevel); public void setLevel(int aLevel);
} }
@@ -1,91 +1,91 @@
package pow.ivyclient; package pow.ivyclient;
import java.net.*; import java.net.*;
import java.util.*; import java.util.*;
import java.util.Calendar; import java.util.Calendar;
/** /**
* inner representation of an ivy bus * inner representation of an ivy bus
* store the drones' information about the drones which belong to this ivy bus * store the drones' information about the drones which belong to this ivy bus
* store the IP adress of the machine where the ivy bus is working * store the IP adress of the machine where the ivy bus is working
*/ */
public class BusIvy_ public class BusIvy_
{ {
private Calendar oCalendar; private Calendar oCalendar;
private long oTime; private long oTime;
private InetAddress busAddress; private InetAddress busAddress;
private ArrayList<Integer> DronesId = new ArrayList<Integer>(); private ArrayList<Integer> DronesId = new ArrayList<Integer>();
/** /**
* *
* @param myInetAddress the ip address of the ivy host * @param myInetAddress the ip address of the ivy host
*/ */
public void setAddress(InetAddress myInetAddress) public void setAddress(InetAddress myInetAddress)
{ {
busAddress = myInetAddress; busAddress = myInetAddress;
} }
/** /**
* update the 'inner clock' of the object when a message for this bus is detected * update the 'inner clock' of the object when a message for this bus is detected
* useful to know if the bus is still alive * useful to know if the bus is still alive
*/ */
public void updateTime() public void updateTime()
{ {
oCalendar=Calendar.getInstance(); oCalendar=Calendar.getInstance();
oTime = oCalendar.getTimeInMillis(); oTime = oCalendar.getTimeInMillis();
} }
/** /**
* inform the bus that a new drone send information on this bus * inform the bus that a new drone send information on this bus
* @param newDroneId (the ivy id) * @param newDroneId (the ivy id)
*/ */
public void addDrones(int newDroneId) public void addDrones(int newDroneId)
{ {
DronesId.add(newDroneId); DronesId.add(newDroneId);
} }
/** /**
* get a array list containing the ivy id of the drones present on the bus * get a array list containing the ivy id of the drones present on the bus
* @return the array list containing the ivy id of the drones present on the bus * @return the array list containing the ivy id of the drones present on the bus
*/ */
public ArrayList<Integer> getDrones() public ArrayList<Integer> getDrones()
{ {
return DronesId; return DronesId;
} }
/** /**
* display information on stdout about the drones present on the bus * display information on stdout about the drones present on the bus
*/ */
public void displayDrones() public void displayDrones()
{ {
System.out.println("Bus Ivy : "); System.out.println("Bus Ivy : ");
System.out.println(busAddress); System.out.println(busAddress);
System.out.println("Drones : "); System.out.println("Drones : ");
for(Integer myDrone : DronesId) for(Integer myDrone : DronesId)
{ {
System.out.println(myDrone); System.out.println(myDrone);
} }
} }
/** /**
* provides the IP adress of the host hosting the bus * provides the IP adress of the host hosting the bus
* @return the IP adress of the host hosting the bus * @return the IP adress of the host hosting the bus
*/ */
public InetAddress getAddress() public InetAddress getAddress()
{ {
return busAddress; return busAddress;
} }
/** /**
* inform if a drone is present or not on the bus * inform if a drone is present or not on the bus
* @param myDroneId the ivy id * @param myDroneId the ivy id
* @return true if the drone is present on the bus * @return true if the drone is present on the bus
*/ */
public boolean isOwnBy(int myDroneId) public boolean isOwnBy(int myDroneId)
{ {
return DronesId.contains(myDroneId); return DronesId.contains(myDroneId);
} }
/** /**
* inform if the bus is alive * inform if the bus is alive
* @return true if the last message was received less than 10 seconds ago * @return true if the last message was received less than 10 seconds ago
*/ */
public boolean isAlive() public boolean isAlive()
{ {
Calendar iCalendar = Calendar.getInstance(); Calendar iCalendar = Calendar.getInstance();
long iTime = iCalendar.getTimeInMillis(); long iTime = iCalendar.getTimeInMillis();
return ((iTime - oTime)<10000); // 10 secondes return ((iTime - oTime)<10000); // 10 secondes
} }
} }
@@ -1,165 +1,165 @@
package pow.webserver; package pow.webserver;
import java.io.*; import java.io.*;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/** /**
* *
* store useful data about the server configuration * store useful data about the server configuration
* and database connection by * and database connection by
* reading a specific file place in the 'conf' folder of * reading a specific file place in the 'conf' folder of
* the web application * the web application
*/ */
public class Conf { public class Conf {
/** The mail of the administrator to contact if any problems occurs /** The mail of the administrator to contact if any problems occurs
* (appears in the help.jsp page. */ * (appears in the help.jsp page. */
private String mailAdmin; private String mailAdmin;
/** The administrator login (not used). */ /** The administrator login (not used). */
private String adminLogin; private String adminLogin;
/** The port in which the module listen to get udp trames from ivy buses. */ /** The port in which the module listen to get udp trames from ivy buses. */
private int portIvyToWeb; private int portIvyToWeb;
/** The dimension of the datagrams received. */ /** The dimension of the datagrams received. */
private int tailleUdpTrame; private int tailleUdpTrame;
/** The passWord of the database */ /** The passWord of the database */
private String dbPassword; private String dbPassword;
/** The userName of the dataBase */ /** The userName of the dataBase */
private String dbUserName; private String dbUserName;
/** The Name of the dataBase */ /** The Name of the dataBase */
private String dataBaseName; private String dataBaseName;
/** The timeout of the connection */ /** The timeout of the connection */
private int udpTimeout; private int udpTimeout;
/** The port in which messages from web are sent to ivy buses */ /** The port in which messages from web are sent to ivy buses */
private int portWebToIvy ; private int portWebToIvy ;
/** period of time in millisec to reset the filter of waypoint_moved messages */ /** period of time in millisec to reset the filter of waypoint_moved messages */
private long time2resetFilter; private long time2resetFilter;
/** period of time in millisec to send all the parameter values for a specific drone */ /** period of time in millisec to send all the parameter values for a specific drone */
private long timeToSendValues; private long timeToSendValues;
/** time to wait for the acknowledgement of an order */ /** time to wait for the acknowledgement of an order */
private int order_response_timeout; private int order_response_timeout;
/** time to wait after a die event to remove the drone */ /** time to wait after a die event to remove the drone */
private int dieEventTimeoutTime; private int dieEventTimeoutTime;
/** time to wait after receiving no data for a drone to remove the drone */ /** time to wait after receiving no data for a drone to remove the drone */
private int dataEventTimeoutTime; private int dataEventTimeoutTime;
/** period of time to check for dead ivy buses in serveur.java*/ /** period of time to check for dead ivy buses in serveur.java*/
private long time2checkDeadBuses; private long time2checkDeadBuses;
/** how the database work VERBOSE or SILENT*/ /** how the database work VERBOSE or SILENT*/
private DbMode dbMode; private DbMode dbMode;
/** /**
* *
* @param default_folder folder of the web application on the server * @param default_folder folder of the web application on the server
* @param conf_filename name of the configuration file placed in 'conf' folder of the web application * @param conf_filename name of the configuration file placed in 'conf' folder of the web application
*/ */
public Conf(String default_folder,String conf_filename) public Conf(String default_folder,String conf_filename)
{ {
try{ try{
DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
// création d'un constructeur de documents // création d'un constructeur de documents
DocumentBuilder constructeur = fabrique.newDocumentBuilder(); DocumentBuilder constructeur = fabrique.newDocumentBuilder();
// lecture du contenu d'un fichier XML avec DOM // lecture du contenu d'un fichier XML avec DOM
File xml = new File(default_folder + "/conf/"+conf_filename); File xml = new File(default_folder + "/conf/"+conf_filename);
Document document = constructeur.parse(xml); Document document = constructeur.parse(xml);
Element mailAdmin_node = (Element)document.getElementsByTagName("mailWebAdmin").item(0); Element mailAdmin_node = (Element)document.getElementsByTagName("mailWebAdmin").item(0);
Element adminLogin_node = (Element)document.getElementsByTagName("webAdminLogin").item(0); Element adminLogin_node = (Element)document.getElementsByTagName("webAdminLogin").item(0);
Element portIvyToWeb_node = (Element)document.getElementsByTagName("portIvyToWeb").item(0); Element portIvyToWeb_node = (Element)document.getElementsByTagName("portIvyToWeb").item(0);
Element taille_node = (Element)document.getElementsByTagName("sizeUdpTrame").item(0); Element taille_node = (Element)document.getElementsByTagName("sizeUdpTrame").item(0);
Element passWord_node = (Element)document.getElementsByTagName("dbPassword").item(0); Element passWord_node = (Element)document.getElementsByTagName("dbPassword").item(0);
Element userName_node = (Element)document.getElementsByTagName("dbUserName").item(0); Element userName_node = (Element)document.getElementsByTagName("dbUserName").item(0);
Element dataBaseName_node = (Element)document.getElementsByTagName("dataBaseName").item(0); Element dataBaseName_node = (Element)document.getElementsByTagName("dataBaseName").item(0);
Element timeout_node = (Element)document.getElementsByTagName("udpSocketTimeout").item(0); Element timeout_node = (Element)document.getElementsByTagName("udpSocketTimeout").item(0);
Element portWebToIvy_node = (Element)document.getElementsByTagName("portWebToIvy").item(0); Element portWebToIvy_node = (Element)document.getElementsByTagName("portWebToIvy").item(0);
Element time2resetFilter_node = (Element)document.getElementsByTagName("time2resetFilter").item(0); Element time2resetFilter_node = (Element)document.getElementsByTagName("time2resetFilter").item(0);
Element timeToSendValuesy_node = (Element)document.getElementsByTagName("timeToSendValues").item(0); Element timeToSendValuesy_node = (Element)document.getElementsByTagName("timeToSendValues").item(0);
Element order_response_timeout_node = (Element)document.getElementsByTagName("order_response_timeout").item(0); Element order_response_timeout_node = (Element)document.getElementsByTagName("order_response_timeout").item(0);
Element dieEventTimeoutTime_node = (Element)document.getElementsByTagName("dieEventTimeoutTime").item(0); Element dieEventTimeoutTime_node = (Element)document.getElementsByTagName("dieEventTimeoutTime").item(0);
Element dataEventTimeoutTime_node = (Element)document.getElementsByTagName("dataEventTimeoutTime").item(0); Element dataEventTimeoutTime_node = (Element)document.getElementsByTagName("dataEventTimeoutTime").item(0);
Element time2checkDeadBuses_node = (Element)document.getElementsByTagName("time2checkDeadBuses").item(0); Element time2checkDeadBuses_node = (Element)document.getElementsByTagName("time2checkDeadBuses").item(0);
Element dbMode_node = (Element)document.getElementsByTagName("dbMode").item(0); Element dbMode_node = (Element)document.getElementsByTagName("dbMode").item(0);
String dbMode_str = dbMode_node.getTextContent(); String dbMode_str = dbMode_node.getTextContent();
if (dbMode_str.equals("verbose")){dbMode = DbMode.VERBOSE;} if (dbMode_str.equals("verbose")){dbMode = DbMode.VERBOSE;}
else {dbMode = DbMode.SILENT;} else {dbMode = DbMode.SILENT;}
mailAdmin=mailAdmin_node.getTextContent(); mailAdmin=mailAdmin_node.getTextContent();
adminLogin=adminLogin_node.getTextContent(); adminLogin=adminLogin_node.getTextContent();
portIvyToWeb=Integer.parseInt(portIvyToWeb_node.getTextContent()); portIvyToWeb=Integer.parseInt(portIvyToWeb_node.getTextContent());
tailleUdpTrame=Integer.parseInt(taille_node.getTextContent()); tailleUdpTrame=Integer.parseInt(taille_node.getTextContent());
dbPassword=passWord_node.getTextContent(); dbPassword=passWord_node.getTextContent();
dbUserName=userName_node.getTextContent(); dbUserName=userName_node.getTextContent();
dataBaseName=dataBaseName_node.getTextContent(); dataBaseName=dataBaseName_node.getTextContent();
udpTimeout=Integer.parseInt(timeout_node.getTextContent()); udpTimeout=Integer.parseInt(timeout_node.getTextContent());
portWebToIvy=Integer.parseInt(portWebToIvy_node.getTextContent()); portWebToIvy=Integer.parseInt(portWebToIvy_node.getTextContent());
time2resetFilter=Long.parseLong(time2resetFilter_node.getTextContent()); time2resetFilter=Long.parseLong(time2resetFilter_node.getTextContent());
timeToSendValues=Long.parseLong(timeToSendValuesy_node.getTextContent()); timeToSendValues=Long.parseLong(timeToSendValuesy_node.getTextContent());
order_response_timeout=Integer.parseInt(order_response_timeout_node.getTextContent()); order_response_timeout=Integer.parseInt(order_response_timeout_node.getTextContent());
dieEventTimeoutTime=Integer.parseInt(dieEventTimeoutTime_node.getTextContent()); dieEventTimeoutTime=Integer.parseInt(dieEventTimeoutTime_node.getTextContent());
dataEventTimeoutTime=Integer.parseInt(dataEventTimeoutTime_node.getTextContent()); dataEventTimeoutTime=Integer.parseInt(dataEventTimeoutTime_node.getTextContent());
time2checkDeadBuses =Integer.parseInt(time2checkDeadBuses_node.getTextContent()); time2checkDeadBuses =Integer.parseInt(time2checkDeadBuses_node.getTextContent());
} catch(ParserConfigurationException pce){ } catch(ParserConfigurationException pce){
System.out.println("error in loading configuration file : "+default_folder + "/conf/"+conf_filename); System.out.println("error in loading configuration file : "+default_folder + "/conf/"+conf_filename);
pce.printStackTrace(); pce.printStackTrace();
}catch(SAXException se){ }catch(SAXException se){
System.out.println("error in loading configuration file : "+default_folder + "/conf/"+conf_filename); System.out.println("error in loading configuration file : "+default_folder + "/conf/"+conf_filename);
se.printStackTrace(); se.printStackTrace();
}catch(IOException ioe){ }catch(IOException ioe){
System.out.println("error in loading configuration file : "+default_folder + "/conf/"+conf_filename); System.out.println("error in loading configuration file : "+default_folder + "/conf/"+conf_filename);
ioe.printStackTrace(); ioe.printStackTrace();
} }
} }
/** @return the udp port on which the server receive data from ivy buses */ /** @return the udp port on which the server receive data from ivy buses */
public int portIvyToWeb() public int portIvyToWeb()
{ {
return portIvyToWeb; return portIvyToWeb;
} }
/** @return the udp port on which the server send data to ivy buses */ /** @return the udp port on which the server send data to ivy buses */
public int portWebToIvy() public int portWebToIvy()
{ {
return portWebToIvy; return portWebToIvy;
} }
/** @return the max size of an udp trame */ /** @return the max size of an udp trame */
public int getUdpSize() public int getUdpSize()
{ {
return tailleUdpTrame; return tailleUdpTrame;
} }
/** @return the password to connect to the database*/ /** @return the password to connect to the database*/
public String getDBPassword() public String getDBPassword()
{ {
return dbPassword; return dbPassword;
} }
/** @return the login to connect to the database*/ /** @return the login to connect to the database*/
public String getDBUserName() public String getDBUserName()
{ {
return dbUserName; return dbUserName;
} }
/** @return the database name*/ /** @return the database name*/
public String getDataBaseName() public String getDataBaseName()
{ {
return dataBaseName; return dataBaseName;
} }
/** @return a time after what an exception is thrown if no message has been received by server*/ /** @return a time after what an exception is thrown if no message has been received by server*/
public int getSocketTimeout() public int getSocketTimeout()
{ {
return udpTimeout; return udpTimeout;
} }
/** @return the mail to contact if any problem occurs */ /** @return the mail to contact if any problem occurs */
public String mailAdmin(){return mailAdmin;} public String mailAdmin(){return mailAdmin;}
/** @return the login of the administrator of the site */ /** @return the login of the administrator of the site */
public String adminLogin(){return adminLogin;} public String adminLogin(){return adminLogin;}
/**@return period of time in millisec to reset the filter of waypoint_moved messages */ /**@return period of time in millisec to reset the filter of waypoint_moved messages */
public long getTime2resetFilter(){return time2resetFilter;} public long getTime2resetFilter(){return time2resetFilter;}
/**@return period of time in millisec to send all the parameter values for a specific drone */ /**@return period of time in millisec to send all the parameter values for a specific drone */
public long getTimeToSendValues(){return timeToSendValues;} public long getTimeToSendValues(){return timeToSendValues;}
/**@return time to wait for the acknowledgement of an order */ /**@return time to wait for the acknowledgement of an order */
public int getOrderResponseTimeout(){return order_response_timeout;} public int getOrderResponseTimeout(){return order_response_timeout;}
/**@return time to wait after a die event to remove the drone */ /**@return time to wait after a die event to remove the drone */
public int getDieEventTimeoutTime(){return dieEventTimeoutTime;} public int getDieEventTimeoutTime(){return dieEventTimeoutTime;}
/**@return time to wait after receiving no data for a drone to remove the drone */ /**@return time to wait after receiving no data for a drone to remove the drone */
public int getDataEventTimeoutTime(){return dataEventTimeoutTime;} public int getDataEventTimeoutTime(){return dataEventTimeoutTime;}
/**@return period of time to check for dead ivy buses in serveur.java*/ /**@return period of time to check for dead ivy buses in serveur.java*/
public long getTime2checkDeadBuses(){return time2checkDeadBuses;} public long getTime2checkDeadBuses(){return time2checkDeadBuses;}
/**@return SILENT or VERBOSE */ /**@return SILENT or VERBOSE */
public DbMode getDbMode(){return dbMode;} public DbMode getDbMode(){return dbMode;}
} }
@@ -1,73 +1,73 @@
package pow.webserver; package pow.webserver;
import java.io.*; import java.io.*;
import java.util.Calendar; import java.util.Calendar;
/** /**
* Handles the writing of a log in a file * Handles the writing of a log in a file
* @author from V1 * @author from V1
* @since V1 * @since V1
*/ */
public class Log { public class Log {
private File oFile = null; private File oFile = null;
private FileWriter oFileWriter = null; private FileWriter oFileWriter = null;
private BufferedWriter oBufferedWriter = null; private BufferedWriter oBufferedWriter = null;
/** /**
* create a log file into the log floder of the web application * create a log file into the log floder of the web application
* @param path the complete path of the web application * @param path the complete path of the web application
*/ */
public Log(String path) public Log(String path)
{ {
Calendar Today = Calendar.getInstance(); Calendar Today = Calendar.getInstance();
String fileName = String.valueOf(Today.get(Calendar.DAY_OF_MONTH)) + String fileName = String.valueOf(Today.get(Calendar.DAY_OF_MONTH)) +
String.valueOf(Today.get(Calendar.MONTH)) + String.valueOf(Today.get(Calendar.MONTH)) +
String.valueOf(Today.get(Calendar.YEAR)) + String.valueOf(Today.get(Calendar.YEAR)) +
String.valueOf(Today.get(Calendar.HOUR_OF_DAY)) + String.valueOf(Today.get(Calendar.HOUR_OF_DAY)) +
String.valueOf(Today.get(Calendar.MINUTE)) + String.valueOf(Today.get(Calendar.MINUTE)) +
String.valueOf(Today.get(Calendar.SECOND)) + String.valueOf(Today.get(Calendar.SECOND)) +
".log"; ".log";
try try
{ {
oFile = new File(path+"/log/" + fileName); oFile = new File(path+"/log/" + fileName);
oFile.createNewFile(); oFile.createNewFile();
oFileWriter = new FileWriter(oFile); oFileWriter = new FileWriter(oFile);
oBufferedWriter = new BufferedWriter(oFileWriter); oBufferedWriter = new BufferedWriter(oFileWriter);
oBufferedWriter.write("##########################################"); oBufferedWriter.newLine(); oBufferedWriter.write("##########################################"); oBufferedWriter.newLine();
oBufferedWriter.write("########## PAPARAZZI ON THE WEB ##########"); oBufferedWriter.newLine(); oBufferedWriter.write("########## PAPARAZZI ON THE WEB ##########"); oBufferedWriter.newLine();
oBufferedWriter.write("##########################################"); oBufferedWriter.newLine(); oBufferedWriter.write("##########################################"); oBufferedWriter.newLine();
oBufferedWriter.newLine(); oBufferedWriter.newLine();
oBufferedWriter.write("Beginning of log : "); oBufferedWriter.newLine(); oBufferedWriter.write("Beginning of log : "); oBufferedWriter.newLine();
oBufferedWriter.newLine(); oBufferedWriter.newLine();
oBufferedWriter.flush(); oBufferedWriter.flush();
} }
catch(IOException ex) catch(IOException ex)
{ {
System.out.println("No log file created "); System.out.println("No log file created ");
ex.printStackTrace(); ex.printStackTrace();
} }
} }
/** /**
* write a string in log file and on stdout * write a string in log file and on stdout
* @param writing the string to write in the log file * @param writing the string to write in the log file
*/ */
public void write(String writing) public void write(String writing)
{ {
Calendar Now = Calendar.getInstance(); Calendar Now = Calendar.getInstance();
String Time = String.valueOf(Now.get(Calendar.HOUR_OF_DAY)) + ":" + String Time = String.valueOf(Now.get(Calendar.HOUR_OF_DAY)) + ":" +
String.valueOf(Now.get(Calendar.MINUTE)) + ":" + String.valueOf(Now.get(Calendar.MINUTE)) + ":" +
String.valueOf(Now.get(Calendar.SECOND)); String.valueOf(Now.get(Calendar.SECOND));
writing = writing.trim(); writing = writing.trim();
try try
{ {
oBufferedWriter.write(Time + " -> " + writing); oBufferedWriter.newLine(); oBufferedWriter.write(Time + " -> " + writing); oBufferedWriter.newLine();
oBufferedWriter.flush(); oBufferedWriter.flush();
System.out.println("\nlog at : " + Time + " -> " + writing); System.out.println("\nlog at : " + Time + " -> " + writing);
} }
catch(IOException ex) catch(IOException ex)
{ {
System.out.println(ex.getMessage()); System.out.println(ex.getMessage());
} }
} }
} }
@@ -1,50 +1,50 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.client; package nl.justobjects.pushlet.client;
import nl.justobjects.pushlet.core.Event; import nl.justobjects.pushlet.core.Event;
import nl.justobjects.pushlet.core.Protocol; import nl.justobjects.pushlet.core.Protocol;
/** /**
* Interface for listener of the PushletClient object. * Interface for listener of the PushletClient object.
* *
* @version $Id: PushletClientListener.java,v 1.5 2005/02/21 11:50:37 justb Exp $ * @version $Id: PushletClientListener.java,v 1.5 2005/02/21 11:50:37 justb Exp $
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
**/ **/
public interface PushletClientListener extends Protocol { public interface PushletClientListener extends Protocol {
/** Abort event from server. */ /** Abort event from server. */
public void onAbort(Event theEvent); public void onAbort(Event theEvent);
/** Data event from server. */ /** Data event from server. */
public void onData(Event theEvent); public void onData(Event theEvent);
/** Heartbeat event from server. */ /** Heartbeat event from server. */
public void onHeartbeat(Event theEvent); public void onHeartbeat(Event theEvent);
/** Error occurred. */ /** Error occurred. */
public void onError(String message); public void onError(String message);
} }
/* /*
* $Log: PushletClientListener.java,v $ * $Log: PushletClientListener.java,v $
* Revision 1.5 2005/02/21 11:50:37 justb * Revision 1.5 2005/02/21 11:50:37 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.4 2005/02/15 15:46:31 justb * Revision 1.4 2005/02/15 15:46:31 justb
* client API improves * client API improves
* *
* Revision 1.3 2004/10/24 12:58:18 justb * Revision 1.3 2004/10/24 12:58:18 justb
* revised client and test classes for new protocol * revised client and test classes for new protocol
* *
* Revision 1.2 2004/09/03 22:35:37 justb * Revision 1.2 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.1 2004/03/10 20:14:17 justb * Revision 1.1 2004/03/10 20:14:17 justb
* renamed all *JavaPushletClient* to *PushletClient* * renamed all *JavaPushletClient* to *PushletClient*
* *
* Revision 1.3 2003/08/15 08:37:40 justb * Revision 1.3 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* *
*/ */
@@ -1,203 +1,203 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.core; package nl.justobjects.pushlet.core;
import nl.justobjects.pushlet.util.Log; import nl.justobjects.pushlet.util.Log;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Iterator; import java.util.Iterator;
/** /**
* Generic implementation of ClientAdapter for browser clients. * Generic implementation of ClientAdapter for browser clients.
* *
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
* @version $Id: BrowserAdapter.java,v 1.6 2007/11/09 13:15:35 justb Exp $ * @version $Id: BrowserAdapter.java,v 1.6 2007/11/09 13:15:35 justb Exp $
*/ */
public class BrowserAdapter implements ClientAdapter, Protocol { public class BrowserAdapter implements ClientAdapter, Protocol {
public static final String START_DOCUMENT = public static final String START_DOCUMENT =
"<html><head><meta http-equiv=\"Pragma\" content=\"no-cache\"><meta http-equiv=\"Expires\" content=\"Tue, 31 Dec 1997 23:59:59 GMT\"></head>" "<html><head><meta http-equiv=\"Pragma\" content=\"no-cache\"><meta http-equiv=\"Expires\" content=\"Tue, 31 Dec 1997 23:59:59 GMT\"></head>"
+ "<body>" + "<body>"
+ "\n<script language=\"JavaScript\"> var url=\" \"; \nfunction refresh() { document.location.href=url; }</script>"; + "\n<script language=\"JavaScript\"> var url=\" \"; \nfunction refresh() { document.location.href=url; }</script>";
public static final String END_DOCUMENT = "</body></html>"; public static final String END_DOCUMENT = "</body></html>";
private PrintWriter servletOut; private PrintWriter servletOut;
private HttpServletResponse servletRsp; private HttpServletResponse servletRsp;
private int bytesSent; private int bytesSent;
/** /**
* Constructor. * Constructor.
*/ */
public BrowserAdapter(HttpServletResponse aServletResponse) { public BrowserAdapter(HttpServletResponse aServletResponse) {
servletRsp = aServletResponse; servletRsp = aServletResponse;
} }
/** /**
* Generic init. * Generic init.
*/ */
public void start() throws IOException { public void start() throws IOException {
// Keep servlet request/response objects until page ends in stop() // Keep servlet request/response objects until page ends in stop()
// Content type as HTML // Content type as HTML
servletRsp.setStatus(HttpServletResponse.SC_OK); servletRsp.setStatus(HttpServletResponse.SC_OK);
servletRsp.setContentType("text/html;charset=UTF-8"); servletRsp.setContentType("text/html;charset=UTF-8");
// http://www.junlu.com/msg/45902.html // http://www.junlu.com/msg/45902.html
// Log.debug("bufsize=" + aRsp.getBufferSize()); // Log.debug("bufsize=" + aRsp.getBufferSize());
servletOut = servletRsp.getWriter(); servletOut = servletRsp.getWriter();
send(START_DOCUMENT); send(START_DOCUMENT);
} }
/** /**
* Push Event to client. * Push Event to client.
*/ */
public void push(Event anEvent) throws IOException { public void push(Event anEvent) throws IOException {
Log.debug("BCA event=" + anEvent.toXML()); Log.debug("BCA event=" + anEvent.toXML());
// Check if we should refresh // Check if we should refresh
if (anEvent.getEventType().equals(Protocol.E_REFRESH)) { if (anEvent.getEventType().equals(Protocol.E_REFRESH)) {
// Append refresh and tail of HTML document // Append refresh and tail of HTML document
// Construct the JS callback line to be sent as last line of doc. // Construct the JS callback line to be sent as last line of doc.
// This will refresh the request using the unique id to determine // This will refresh the request using the unique id to determine
// the subscriber instance on the server. The client will wait for // the subscriber instance on the server. The client will wait for
// a number of milliseconds. // a number of milliseconds.
long refreshWaitMillis = Long.parseLong(anEvent.getField(P_WAIT)); long refreshWaitMillis = Long.parseLong(anEvent.getField(P_WAIT));
// Create servlet request for requesting next events (refresh) // Create servlet request for requesting next events (refresh)
String url = anEvent.getField(P_URL); String url = anEvent.getField(P_URL);
String jsRefreshTrigger = "\n<script language=\"JavaScript\">url=\'" + url + "\';\n setTimeout(\"refresh()\", " + refreshWaitMillis + ");\n</script>"; String jsRefreshTrigger = "\n<script language=\"JavaScript\">url=\'" + url + "\';\n setTimeout(\"refresh()\", " + refreshWaitMillis + ");\n</script>";
send(jsRefreshTrigger + END_DOCUMENT); send(jsRefreshTrigger + END_DOCUMENT);
} else { } else {
send(event2JavaScript(anEvent)); send(event2JavaScript(anEvent));
} }
} }
/** /**
* End HTML page in client browser. * End HTML page in client browser.
*/ */
public void stop() { public void stop() {
// To be garbage collected if adapter remains active // To be garbage collected if adapter remains active
servletOut = null; servletOut = null;
} }
/** /**
* Send any string to browser. * Send any string to browser.
*/ */
protected void send(String s) throws IOException { protected void send(String s) throws IOException {
// Send string to browser. // Send string to browser.
// Log.debug("Adapter: sending: " + s); // Log.debug("Adapter: sending: " + s);
if (servletOut == null) { if (servletOut == null) {
throw new IOException("Client adapter was stopped"); throw new IOException("Client adapter was stopped");
} }
servletOut.print(s); servletOut.print(s);
servletOut.flush(); servletOut.flush();
// Note: this doesn't seem to have effect // Note: this doesn't seem to have effect
// in Tomcat 4/5 if the client already disconnected. // in Tomcat 4/5 if the client already disconnected.
servletRsp.flushBuffer(); servletRsp.flushBuffer();
bytesSent += s.length(); bytesSent += s.length();
Log.debug("bytesSent= " + bytesSent); Log.debug("bytesSent= " + bytesSent);
// Log.debug("BCA sent event: " + s); // Log.debug("BCA sent event: " + s);
} }
/** /**
* Converts the Java Event to a JavaScript function call in browser page. * Converts the Java Event to a JavaScript function call in browser page.
*/ */
protected String event2JavaScript(Event event) throws IOException { protected String event2JavaScript(Event event) throws IOException {
// Convert the event to a comma-separated string. // Convert the event to a comma-separated string.
String jsArgs = ""; String jsArgs = "";
for (Iterator iter = event.getFieldNames(); iter.hasNext();) { for (Iterator iter = event.getFieldNames(); iter.hasNext();) {
String name = (String) iter.next(); String name = (String) iter.next();
String value = event.getField(name); String value = event.getField(name);
String nextArgument = (jsArgs.equals("") ? "" : ",") + "'" + name + "'" + ", \"" + value + "\""; String nextArgument = (jsArgs.equals("") ? "" : ",") + "'" + name + "'" + ", \"" + value + "\"";
jsArgs += nextArgument; jsArgs += nextArgument;
} }
// Construct and return the function call */ // Construct and return the function call */
return "<script language=\"JavaScript\">parent.push(" + jsArgs + ");</script>"; return "<script language=\"JavaScript\">parent.push(" + jsArgs + ");</script>";
} }
} }
/* /*
* $Log: BrowserAdapter.java,v $ * $Log: BrowserAdapter.java,v $
* Revision 1.6 2007/11/09 13:15:35 justb * Revision 1.6 2007/11/09 13:15:35 justb
* add charset=UTF-8 in returned HTTP content types * add charset=UTF-8 in returned HTTP content types
* *
* Revision 1.5 2006/05/15 11:52:53 justb * Revision 1.5 2006/05/15 11:52:53 justb
* updates mainly for AJAX client * updates mainly for AJAX client
* *
* Revision 1.4 2006/05/06 00:10:11 justb * Revision 1.4 2006/05/06 00:10:11 justb
* various chgs but not too serious... * various chgs but not too serious...
* *
* Revision 1.3 2005/02/28 12:45:59 justb * Revision 1.3 2005/02/28 12:45:59 justb
* introduced Command class * introduced Command class
* *
* Revision 1.2 2005/02/21 11:50:44 justb * Revision 1.2 2005/02/21 11:50:44 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.1 2005/02/18 10:07:23 justb * Revision 1.1 2005/02/18 10:07:23 justb
* many renamings of classes (make names compact) * many renamings of classes (make names compact)
* *
* Revision 1.12 2005/02/15 13:30:23 justb * Revision 1.12 2005/02/15 13:30:23 justb
* changes for Tomcat buffering (now working in tc4 and 5.0) * changes for Tomcat buffering (now working in tc4 and 5.0)
* *
* Revision 1.11 2005/01/24 22:45:58 justb * Revision 1.11 2005/01/24 22:45:58 justb
* getting safari to work * getting safari to work
* *
* Revision 1.10 2005/01/18 16:46:27 justb * Revision 1.10 2005/01/18 16:46:27 justb
* buffer size setting ignored by tomcat workings * buffer size setting ignored by tomcat workings
* *
* Revision 1.9 2004/10/24 12:58:18 justb * Revision 1.9 2004/10/24 12:58:18 justb
* revised client and test classes for new protocol * revised client and test classes for new protocol
* *
* Revision 1.8 2004/09/20 22:01:38 justb * Revision 1.8 2004/09/20 22:01:38 justb
* more changes for new protocol * more changes for new protocol
* *
* Revision 1.7 2004/09/03 22:35:37 justb * Revision 1.7 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.6 2004/08/15 16:00:15 justb * Revision 1.6 2004/08/15 16:00:15 justb
* enhancements to pull mode * enhancements to pull mode
* *
* Revision 1.5 2004/08/13 23:36:05 justb * Revision 1.5 2004/08/13 23:36:05 justb
* rewrite of Pullet into Pushlet "pull" mode * rewrite of Pullet into Pushlet "pull" mode
* *
* Revision 1.4 2003/08/15 08:37:40 justb * Revision 1.4 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.3 2003/08/12 09:57:05 justb * Revision 1.3 2003/08/12 09:57:05 justb
* replaced all print statements to Log.*() calls * replaced all print statements to Log.*() calls
* *
* Revision 1.2 2003/05/18 16:15:07 justb * Revision 1.2 2003/05/18 16:15:07 justb
* support for XML encoded Events * support for XML encoded Events
* *
* Revision 1.1.1.1 2002/09/24 21:02:30 justb * Revision 1.1.1.1 2002/09/24 21:02:30 justb
* import to sourceforge * import to sourceforge
* *
* Revision 1.1.1.1 2002/09/20 22:48:17 justb * Revision 1.1.1.1 2002/09/20 22:48:17 justb
* import to SF * import to SF
* *
* Revision 1.1.1.1 2002/09/20 14:19:02 justb * Revision 1.1.1.1 2002/09/20 14:19:02 justb
* first import into SF * first import into SF
* *
* Revision 1.5 2002/04/15 20:42:41 just * Revision 1.5 2002/04/15 20:42:41 just
* reformatting and renaming GuardedQueue to EventQueue * reformatting and renaming GuardedQueue to EventQueue
* *
* Revision 1.4 2000/12/27 22:39:35 just * Revision 1.4 2000/12/27 22:39:35 just
* no message * no message
* *
* Revision 1.3 2000/10/30 14:15:47 just * Revision 1.3 2000/10/30 14:15:47 just
* no message * no message
* *
* *
*/ */
@@ -1,72 +1,72 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.core; package nl.justobjects.pushlet.core;
import java.io.IOException; import java.io.IOException;
/** /**
* Adapter interface for encapsulation of specific HTTP clients. * Adapter interface for encapsulation of specific HTTP clients.
* *
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
* @version $Id: ClientAdapter.java,v 1.8 2007/11/23 14:33:07 justb Exp $ * @version $Id: ClientAdapter.java,v 1.8 2007/11/23 14:33:07 justb Exp $
*/ */
public interface ClientAdapter { public interface ClientAdapter {
/** /**
* Start event push. * Start event push.
*/ */
public void start() throws IOException; public void start() throws IOException;
/** /**
* Push single Event to client. * Push single Event to client.
*/ */
public void push(Event anEvent) throws IOException; public void push(Event anEvent) throws IOException;
/** /**
* Stop event push. * Stop event push.
*/ */
public void stop() throws IOException; public void stop() throws IOException;
} }
/* /*
* $Log: ClientAdapter.java,v $ * $Log: ClientAdapter.java,v $
* Revision 1.8 2007/11/23 14:33:07 justb * Revision 1.8 2007/11/23 14:33:07 justb
* core classes now configurable through factory * core classes now configurable through factory
* *
* Revision 1.7 2005/02/28 12:45:59 justb * Revision 1.7 2005/02/28 12:45:59 justb
* introduced Command class * introduced Command class
* *
* Revision 1.6 2005/02/21 11:50:45 justb * Revision 1.6 2005/02/21 11:50:45 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.5 2005/02/18 10:07:23 justb * Revision 1.5 2005/02/18 10:07:23 justb
* many renamings of classes (make names compact) * many renamings of classes (make names compact)
* *
* Revision 1.4 2004/09/03 22:35:37 justb * Revision 1.4 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.3 2003/08/15 08:37:40 justb * Revision 1.3 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.2 2003/05/18 16:15:08 justb * Revision 1.2 2003/05/18 16:15:08 justb
* support for XML encoded Events * support for XML encoded Events
* *
* Revision 1.1.1.1 2002/09/24 21:02:30 justb * Revision 1.1.1.1 2002/09/24 21:02:30 justb
* import to sourceforge * import to sourceforge
* *
* Revision 1.1.1.1 2002/09/20 22:48:17 justb * Revision 1.1.1.1 2002/09/20 22:48:17 justb
* import to SF * import to SF
* *
* Revision 1.1.1.1 2002/09/20 14:19:03 justb * Revision 1.1.1.1 2002/09/20 14:19:03 justb
* first import into SF * first import into SF
* *
* Revision 1.3 2002/04/15 20:42:41 just * Revision 1.3 2002/04/15 20:42:41 just
* reformatting and renaming GuardedQueue to EventQueue * reformatting and renaming GuardedQueue to EventQueue
* *
* Revision 1.2 2000/08/21 20:48:29 just * Revision 1.2 2000/08/21 20:48:29 just
* added CVS log and id tags plus copyrights * added CVS log and id tags plus copyrights
* *
* *
*/ */
@@ -1,184 +1,184 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.core; package nl.justobjects.pushlet.core;
import nl.justobjects.pushlet.util.Sys; import nl.justobjects.pushlet.util.Sys;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
/** /**
* Represents the event data. * Represents the event data.
* *
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
* @version $Id: Event.java,v 1.13 2007/11/23 14:33:07 justb Exp $ * @version $Id: Event.java,v 1.13 2007/11/23 14:33:07 justb Exp $
*/ */
public class Event implements Protocol, Serializable { public class Event implements Protocol, Serializable {
protected Map attributes = new HashMap(3); protected Map attributes = new HashMap(3);
public Event(String anEventType) { public Event(String anEventType) {
this(anEventType, null); this(anEventType, null);
} }
public Event(String anEventType, Map theAttributes) { public Event(String anEventType, Map theAttributes) {
if (theAttributes != null) { if (theAttributes != null) {
setAttrs(theAttributes); setAttrs(theAttributes);
} }
// Set required field event type // Set required field event type
setField(P_EVENT, anEventType); setField(P_EVENT, anEventType);
// Set time in seconds since 1970 // Set time in seconds since 1970
setField(P_TIME, System.currentTimeMillis() / 1000); setField(P_TIME, System.currentTimeMillis() / 1000);
} }
public Event(Map theAttributes) { public Event(Map theAttributes) {
if (!theAttributes.containsKey(P_EVENT)) { if (!theAttributes.containsKey(P_EVENT)) {
throw new IllegalArgumentException(P_EVENT + " not found in attributes"); throw new IllegalArgumentException(P_EVENT + " not found in attributes");
} }
setAttrs(theAttributes); setAttrs(theAttributes);
} }
public static Event createDataEvent(String aSubject) { public static Event createDataEvent(String aSubject) {
return createDataEvent(aSubject, null); return createDataEvent(aSubject, null);
} }
public static Event createDataEvent(String aSubject, Map theAttributes) { public static Event createDataEvent(String aSubject, Map theAttributes) {
Event dataEvent = new Event(E_DATA, theAttributes); Event dataEvent = new Event(E_DATA, theAttributes);
dataEvent.setField(P_SUBJECT, aSubject); dataEvent.setField(P_SUBJECT, aSubject);
return dataEvent; return dataEvent;
} }
public String getEventType() { public String getEventType() {
return getField(P_EVENT); return getField(P_EVENT);
} }
public String getSubject() { public String getSubject() {
return getField(P_SUBJECT); return getField(P_SUBJECT);
} }
public void setField(String name, String value) { public void setField(String name, String value) {
attributes.put(name, value); attributes.put(name, value);
} }
public void setField(String name, int value) { public void setField(String name, int value) {
attributes.put(name, value + ""); attributes.put(name, value + "");
} }
public void setField(String name, long value) { public void setField(String name, long value) {
attributes.put(name, value + ""); attributes.put(name, value + "");
} }
public String getField(String name) { public String getField(String name) {
return (String) attributes.get(name); return (String) attributes.get(name);
} }
/** /**
* Return field; if null return default. * Return field; if null return default.
*/ */
public String getField(String name, String aDefault) { public String getField(String name, String aDefault) {
String result = getField(name); String result = getField(name);
return result == null ? aDefault : result; return result == null ? aDefault : result;
} }
public Iterator getFieldNames() { public Iterator getFieldNames() {
return attributes.keySet().iterator(); return attributes.keySet().iterator();
} }
public String toString() { public String toString() {
return attributes.toString(); return attributes.toString();
} }
/** /**
* Convert to HTTP query string. * Convert to HTTP query string.
*/ */
public String toQueryString() { public String toQueryString() {
String queryString = ""; String queryString = "";
String amp = ""; String amp = "";
for (Iterator iter = getFieldNames(); iter.hasNext();) { for (Iterator iter = getFieldNames(); iter.hasNext();) {
String nextAttrName = (String) iter.next(); String nextAttrName = (String) iter.next();
String nextAttrValue = getField(nextAttrName); String nextAttrValue = getField(nextAttrName);
queryString = queryString + amp + nextAttrName + "=" + nextAttrValue; queryString = queryString + amp + nextAttrName + "=" + nextAttrValue;
// After first add "&". // After first add "&".
amp = "&"; amp = "&";
} }
return queryString; return queryString;
} }
public String toXML(boolean strict) { public String toXML(boolean strict) {
String xmlString = "<event "; String xmlString = "<event ";
for (Iterator iter = getFieldNames(); iter.hasNext();) { for (Iterator iter = getFieldNames(); iter.hasNext();) {
String nextAttrName = (String) iter.next(); String nextAttrName = (String) iter.next();
String nextAttrValue = getField(nextAttrName); String nextAttrValue = getField(nextAttrName);
xmlString = xmlString + nextAttrName + "=\"" + (strict ? Sys.forHTMLTag(nextAttrValue) : nextAttrValue) + "\" "; xmlString = xmlString + nextAttrName + "=\"" + (strict ? Sys.forHTMLTag(nextAttrValue) : nextAttrValue) + "\" ";
} }
xmlString += "/>"; xmlString += "/>";
return xmlString; return xmlString;
} }
public String toXML() { public String toXML() {
return toXML(false); return toXML(false);
} }
public Object clone() { public Object clone() {
// Clone the Event by using copy constructor // Clone the Event by using copy constructor
return new Event(attributes); return new Event(attributes);
} }
/** /**
* Copy given attributes into event attributes * Copy given attributes into event attributes
*/ */
private void setAttrs(Map theAttributes) { private void setAttrs(Map theAttributes) {
attributes.putAll(theAttributes); attributes.putAll(theAttributes);
} }
} }
/* /*
* $Log: Event.java,v $ * $Log: Event.java,v $
* Revision 1.13 2007/11/23 14:33:07 justb * Revision 1.13 2007/11/23 14:33:07 justb
* core classes now configurable through factory * core classes now configurable through factory
* *
* Revision 1.12 2006/05/15 11:52:53 justb * Revision 1.12 2006/05/15 11:52:53 justb
* updates mainly for AJAX client * updates mainly for AJAX client
* *
* Revision 1.11 2006/05/06 00:06:28 justb * Revision 1.11 2006/05/06 00:06:28 justb
* first rough version AJAX client * first rough version AJAX client
* *
* Revision 1.10 2005/02/21 11:50:46 justb * Revision 1.10 2005/02/21 11:50:46 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.9 2005/02/20 13:05:32 justb * Revision 1.9 2005/02/20 13:05:32 justb
* removed the Postlet (integrated in Pushlet protocol) * removed the Postlet (integrated in Pushlet protocol)
* *
* Revision 1.8 2005/02/15 13:29:24 justb * Revision 1.8 2005/02/15 13:29:24 justb
* add toQueryString() * add toQueryString()
* *
* Revision 1.7 2005/01/18 16:47:10 justb * Revision 1.7 2005/01/18 16:47:10 justb
* protocol changes for v2 and publishing from pushlet client * protocol changes for v2 and publishing from pushlet client
* *
* Revision 1.6 2005/01/13 14:47:15 justb * Revision 1.6 2005/01/13 14:47:15 justb
* control evt: send response on same (control) connection * control evt: send response on same (control) connection
* *
* Revision 1.5 2004/09/03 22:35:37 justb * Revision 1.5 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.4 2004/08/15 16:00:15 justb * Revision 1.4 2004/08/15 16:00:15 justb
* enhancements to pull mode * enhancements to pull mode
* *
* Revision 1.3 2003/08/15 08:37:40 justb * Revision 1.3 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.2 2003/05/18 16:15:08 justb * Revision 1.2 2003/05/18 16:15:08 justb
* support for XML encoded Events * support for XML encoded Events
* *
* Revision 1.1.1.1 2002/09/24 21:02:30 justb * Revision 1.1.1.1 2002/09/24 21:02:30 justb
* import to sourceforge * import to sourceforge
* *
*/ */
@@ -1,185 +1,185 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.core; package nl.justobjects.pushlet.core;
import nl.justobjects.pushlet.util.Log; import nl.justobjects.pushlet.util.Log;
/** /**
* Abstract Event source from which Events are pulled. * Abstract Event source from which Events are pulled.
* *
* @version $Id: EventPullSource.java,v 1.15 2007/11/23 14:33:07 justb Exp $ * @version $Id: EventPullSource.java,v 1.15 2007/11/23 14:33:07 justb Exp $
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
**/ **/
/** /**
* ABC for specifc EventPullSources. * ABC for specifc EventPullSources.
*/ */
abstract public class EventPullSource implements EventSource, Runnable { abstract public class EventPullSource implements EventSource, Runnable {
private volatile boolean alive = false; private volatile boolean alive = false;
private volatile boolean active = false; private volatile boolean active = false;
private static int threadNum = 0; private static int threadNum = 0;
private Thread thread; private Thread thread;
public EventPullSource() { public EventPullSource() {
} }
abstract protected long getSleepTime(); abstract protected long getSleepTime();
abstract protected Event pullEvent(); abstract protected Event pullEvent();
public void start() { public void start() {
thread = new Thread(this, "EventPullSource-" + (++threadNum)); thread = new Thread(this, "EventPullSource-" + (++threadNum));
thread.setDaemon(true); thread.setDaemon(true);
thread.start(); thread.start();
} }
public boolean isAlive() { public boolean isAlive() {
return alive; return alive;
} }
/** /**
* Stop the event generator thread. * Stop the event generator thread.
*/ */
public void stop() { public void stop() {
alive = false; alive = false;
if (thread != null) { if (thread != null) {
thread.interrupt(); thread.interrupt();
thread = null; thread = null;
} }
} }
/** /**
* Activate the event generator thread. * Activate the event generator thread.
*/ */
synchronized public void activate() { synchronized public void activate() {
if (active) { if (active) {
return; return;
} }
active = true; active = true;
if (!alive) { if (!alive) {
start(); start();
return; return;
} }
Log.debug(getClass().getName() + ": notifying..."); Log.debug(getClass().getName() + ": notifying...");
notifyAll(); notifyAll();
} }
/** /**
* Deactivate the event generator thread. * Deactivate the event generator thread.
*/ */
public void passivate() { public void passivate() {
if (!active) { if (!active) {
return; return;
} }
active = false; active = false;
} }
/** /**
* Main loop: sleep, generate event and publish. * Main loop: sleep, generate event and publish.
*/ */
public void run() { public void run() {
Log.debug(getClass().getName() + ": starting..."); Log.debug(getClass().getName() + ": starting...");
alive = true; alive = true;
while (alive) { while (alive) {
try { try {
Thread.sleep(getSleepTime()); Thread.sleep(getSleepTime());
// Stopped during sleep: end loop. // Stopped during sleep: end loop.
if (!alive) { if (!alive) {
break; break;
} }
// If passivated wait until we get // If passivated wait until we get
// get notify()-ied. If there are no subscribers // get notify()-ied. If there are no subscribers
// it wasts CPU to remain producing events... // it wasts CPU to remain producing events...
synchronized (this) { synchronized (this) {
while (!active) { while (!active) {
Log.debug(getClass().getName() + ": waiting..."); Log.debug(getClass().getName() + ": waiting...");
wait(); wait();
} }
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
break; break;
} }
try { try {
// Derived class should produce an event. // Derived class should produce an event.
Event event = pullEvent(); Event event = pullEvent();
// Let the publisher push it to subscribers. // Let the publisher push it to subscribers.
Dispatcher.getInstance().multicast(event); Dispatcher.getInstance().multicast(event);
} catch (Throwable t) { } catch (Throwable t) {
Log.warn("EventPullSource exception while multicasting ", t); Log.warn("EventPullSource exception while multicasting ", t);
t.printStackTrace(); t.printStackTrace();
} }
} }
Log.debug(getClass().getName() + ": stopped"); Log.debug(getClass().getName() + ": stopped");
} }
} }
/* /*
* $Log: EventPullSource.java,v $ * $Log: EventPullSource.java,v $
* Revision 1.15 2007/11/23 14:33:07 justb * Revision 1.15 2007/11/23 14:33:07 justb
* core classes now configurable through factory * core classes now configurable through factory
* *
* Revision 1.14 2005/02/28 09:14:55 justb * Revision 1.14 2005/02/28 09:14:55 justb
* sessmgr/dispatcher factory/singleton support * sessmgr/dispatcher factory/singleton support
* *
* Revision 1.13 2005/02/21 16:59:08 justb * Revision 1.13 2005/02/21 16:59:08 justb
* SessionManager and session lease introduced * SessionManager and session lease introduced
* *
* Revision 1.12 2005/02/21 11:50:46 justb * Revision 1.12 2005/02/21 11:50:46 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.11 2005/02/18 10:07:23 justb * Revision 1.11 2005/02/18 10:07:23 justb
* many renamings of classes (make names compact) * many renamings of classes (make names compact)
* *
* Revision 1.10 2005/02/18 09:54:15 justb * Revision 1.10 2005/02/18 09:54:15 justb
* refactor: rename Publisher Dispatcher and single Subscriber class * refactor: rename Publisher Dispatcher and single Subscriber class
* *
* Revision 1.9 2004/09/20 22:01:38 justb * Revision 1.9 2004/09/20 22:01:38 justb
* more changes for new protocol * more changes for new protocol
* *
* Revision 1.8 2004/09/03 22:35:37 justb * Revision 1.8 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.7 2004/08/15 16:00:15 justb * Revision 1.7 2004/08/15 16:00:15 justb
* enhancements to pull mode * enhancements to pull mode
* *
* Revision 1.6 2004/08/13 23:36:05 justb * Revision 1.6 2004/08/13 23:36:05 justb
* rewrite of Pullet into Pushlet "pull" mode * rewrite of Pullet into Pushlet "pull" mode
* *
* Revision 1.5 2004/03/10 14:01:55 justb * Revision 1.5 2004/03/10 14:01:55 justb
* formatting and *Subscriber refactoring * formatting and *Subscriber refactoring
* *
* Revision 1.4 2003/08/15 08:37:40 justb * Revision 1.4 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.3 2003/08/12 09:57:05 justb * Revision 1.3 2003/08/12 09:57:05 justb
* replaced all print statements to Log.*() calls * replaced all print statements to Log.*() calls
* *
* Revision 1.2 2003/05/18 16:15:08 justb * Revision 1.2 2003/05/18 16:15:08 justb
* support for XML encoded Events * support for XML encoded Events
* *
* Revision 1.1.1.1 2002/09/24 21:02:31 justb * Revision 1.1.1.1 2002/09/24 21:02:31 justb
* import to sourceforge * import to sourceforge
* *
* Revision 1.1.1.1 2002/09/20 22:48:17 justb * Revision 1.1.1.1 2002/09/20 22:48:17 justb
* import to SF * import to SF
* *
* Revision 1.1.1.1 2002/09/20 14:19:03 justb * Revision 1.1.1.1 2002/09/20 14:19:03 justb
* first import into SF * first import into SF
* *
* Revision 1.3 2002/04/15 20:42:41 just * Revision 1.3 2002/04/15 20:42:41 just
* reformatting and renaming GuardedQueue to EventQueue * reformatting and renaming GuardedQueue to EventQueue
* *
* Revision 1.2 2000/08/21 20:48:29 just * Revision 1.2 2000/08/21 20:48:29 just
* added CVS log and id tags plus copyrights * added CVS log and id tags plus copyrights
* *
* *
*/ */
@@ -1,70 +1,70 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.core; package nl.justobjects.pushlet.core;
/** /**
* Abstract Event source from which Events are pulled. * Abstract Event source from which Events are pulled.
* *
* @version $Id: EventSource.java,v 1.7 2007/11/23 14:33:07 justb Exp $ * @version $Id: EventSource.java,v 1.7 2007/11/23 14:33:07 justb Exp $
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
**/ **/
/** /**
* Interface for specifc Event(Pull/Push)Sources. * Interface for specifc Event(Pull/Push)Sources.
*/ */
public interface EventSource { public interface EventSource {
/** /**
* Activate the event source. * Activate the event source.
*/ */
public void activate(); public void activate();
/** /**
* Deactivate the event source. * Deactivate the event source.
*/ */
public void passivate(); public void passivate();
/** /**
* Halt the event source. * Halt the event source.
*/ */
public void stop(); public void stop();
} }
/* /*
* $Log: EventSource.java,v $ * $Log: EventSource.java,v $
* Revision 1.7 2007/11/23 14:33:07 justb * Revision 1.7 2007/11/23 14:33:07 justb
* core classes now configurable through factory * core classes now configurable through factory
* *
* Revision 1.6 2005/02/21 11:50:46 justb * Revision 1.6 2005/02/21 11:50:46 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.5 2005/02/18 10:07:23 justb * Revision 1.5 2005/02/18 10:07:23 justb
* many renamings of classes (make names compact) * many renamings of classes (make names compact)
* *
* Revision 1.4 2004/09/03 22:35:37 justb * Revision 1.4 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.3 2003/08/15 08:37:40 justb * Revision 1.3 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.2 2003/05/18 16:15:08 justb * Revision 1.2 2003/05/18 16:15:08 justb
* support for XML encoded Events * support for XML encoded Events
* *
* Revision 1.1.1.1 2002/09/24 21:02:31 justb * Revision 1.1.1.1 2002/09/24 21:02:31 justb
* import to sourceforge * import to sourceforge
* *
* Revision 1.1.1.1 2002/09/20 22:48:17 justb * Revision 1.1.1.1 2002/09/20 22:48:17 justb
* import to SF * import to SF
* *
* Revision 1.1.1.1 2002/09/20 14:19:03 justb * Revision 1.1.1.1 2002/09/20 14:19:03 justb
* first import into SF * first import into SF
* *
* Revision 1.3 2002/04/15 20:42:41 just * Revision 1.3 2002/04/15 20:42:41 just
* reformatting and renaming GuardedQueue to EventQueue * reformatting and renaming GuardedQueue to EventQueue
* *
* Revision 1.2 2000/08/21 20:48:29 just * Revision 1.2 2000/08/21 20:48:29 just
* added CVS log and id tags plus copyrights * added CVS log and id tags plus copyrights
* *
* *
*/ */
@@ -1,169 +1,169 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.core; package nl.justobjects.pushlet.core;
import nl.justobjects.pushlet.util.Log; import nl.justobjects.pushlet.util.Log;
import nl.justobjects.pushlet.util.Sys; import nl.justobjects.pushlet.util.Sys;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Properties; import java.util.Properties;
import java.util.Vector; import java.util.Vector;
import java.io.File; import java.io.File;
/** /**
* Maintains lifecycle of event sources. * Maintains lifecycle of event sources.
* *
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
* @version $Id: EventSourceManager.java,v 1.14 2007/11/10 13:44:02 justb Exp $ * @version $Id: EventSourceManager.java,v 1.14 2007/11/10 13:44:02 justb Exp $
*/ */
public class EventSourceManager { public class EventSourceManager {
private static Vector eventSources = new Vector(0); private static Vector eventSources = new Vector(0);
private static final String PROPERTIES_FILE = "sources.properties"; private static final String PROPERTIES_FILE = "sources.properties";
/** /**
* Initialize event sources from properties file. * Initialize event sources from properties file.
*/ */
public static void start(String aDirPath) { public static void start(String aDirPath) {
// Load Event sources using properties file. // Load Event sources using properties file.
Log.info("EventSourceManager: start"); Log.info("EventSourceManager: start");
Properties properties = null; Properties properties = null;
try { try {
properties = Sys.loadPropertiesResource(PROPERTIES_FILE); properties = Sys.loadPropertiesResource(PROPERTIES_FILE);
} catch (Throwable t) { } catch (Throwable t) {
// Try from provided dir (e.g. WEB_INF/pushlet.properties) // Try from provided dir (e.g. WEB_INF/pushlet.properties)
String filePath = aDirPath + File.separator + PROPERTIES_FILE; String filePath = aDirPath + File.separator + PROPERTIES_FILE;
Log.info("EventSourceManager: cannot load " + PROPERTIES_FILE + " from classpath, will try from " + filePath); Log.info("EventSourceManager: cannot load " + PROPERTIES_FILE + " from classpath, will try from " + filePath);
try { try {
properties = Sys.loadPropertiesFile(filePath); properties = Sys.loadPropertiesFile(filePath);
} catch (Throwable t2) { } catch (Throwable t2) {
Log.fatal("EventSourceManager: cannot load properties file from " + filePath, t); Log.fatal("EventSourceManager: cannot load properties file from " + filePath, t);
// Give up // Give up
Log.warn("EventSourceManager: not starting local event sources (maybe that is what you want)"); Log.warn("EventSourceManager: not starting local event sources (maybe that is what you want)");
return; return;
} }
} }
// Create event source collection // Create event source collection
eventSources = new Vector(properties.size()); eventSources = new Vector(properties.size());
// Add the configured sources // Add the configured sources
for (Enumeration e = properties.keys(); e.hasMoreElements();) { for (Enumeration e = properties.keys(); e.hasMoreElements();) {
String nextKey = (String) e.nextElement(); String nextKey = (String) e.nextElement();
String nextClass = properties.getProperty(nextKey); String nextClass = properties.getProperty(nextKey);
EventSource nextEventSource = null; EventSource nextEventSource = null;
try { try {
nextEventSource = (EventSource) Class.forName(nextClass).newInstance(); nextEventSource = (EventSource) Class.forName(nextClass).newInstance();
Log.info("created EventSource: key=" + nextKey + " class=" + nextClass); Log.info("created EventSource: key=" + nextKey + " class=" + nextClass);
eventSources.addElement(nextEventSource); eventSources.addElement(nextEventSource);
} catch (Exception ex) { } catch (Exception ex) {
Log.warn("Cannot create EventSource: class=" + nextClass, ex); Log.warn("Cannot create EventSource: class=" + nextClass, ex);
} }
} }
activate(); activate();
} }
/** /**
* Activate all event sources. * Activate all event sources.
*/ */
public static void activate() { public static void activate() {
Log.info("Activating " + eventSources.size() + " EventSources"); Log.info("Activating " + eventSources.size() + " EventSources");
for (int i = 0; i < eventSources.size(); i++) { for (int i = 0; i < eventSources.size(); i++) {
((EventSource) eventSources.elementAt(i)).activate(); ((EventSource) eventSources.elementAt(i)).activate();
} }
Log.info("EventSources activated"); Log.info("EventSources activated");
} }
/** /**
* Deactivate all event sources. * Deactivate all event sources.
*/ */
public static void passivate() { public static void passivate() {
Log.info("Passivating " + eventSources.size() + " EventSources"); Log.info("Passivating " + eventSources.size() + " EventSources");
for (int i = 0; i < eventSources.size(); i++) { for (int i = 0; i < eventSources.size(); i++) {
((EventSource) eventSources.elementAt(i)).passivate(); ((EventSource) eventSources.elementAt(i)).passivate();
} }
Log.info("EventSources passivated"); Log.info("EventSources passivated");
} }
/** /**
* Halt event sources. * Halt event sources.
*/ */
public static void stop() { public static void stop() {
Log.info("Stopping " + eventSources.size() + " EventSources..."); Log.info("Stopping " + eventSources.size() + " EventSources...");
for (int i = 0; i < eventSources.size(); i++) { for (int i = 0; i < eventSources.size(); i++) {
((EventSource) eventSources.elementAt(i)).stop(); ((EventSource) eventSources.elementAt(i)).stop();
} }
Log.info("EventSources stopped"); Log.info("EventSources stopped");
} }
} }
/* /*
* $Log: EventSourceManager.java,v $ * $Log: EventSourceManager.java,v $
* Revision 1.14 2007/11/10 13:44:02 justb * Revision 1.14 2007/11/10 13:44:02 justb
* pushlet.properties and sources.properties can now also be put under WEB-INF * pushlet.properties and sources.properties can now also be put under WEB-INF
* *
* Revision 1.13 2005/02/21 11:50:46 justb * Revision 1.13 2005/02/21 11:50:46 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.12 2005/02/18 12:36:47 justb * Revision 1.12 2005/02/18 12:36:47 justb
* changes for renaming and configurability * changes for renaming and configurability
* *
* Revision 1.11 2005/02/18 10:07:23 justb * Revision 1.11 2005/02/18 10:07:23 justb
* many renamings of classes (make names compact) * many renamings of classes (make names compact)
* *
* Revision 1.10 2005/02/15 13:29:49 justb * Revision 1.10 2005/02/15 13:29:49 justb
* use Sys.loadPropertiesResource() * use Sys.loadPropertiesResource()
* *
* Revision 1.9 2004/09/20 22:01:38 justb * Revision 1.9 2004/09/20 22:01:38 justb
* more changes for new protocol * more changes for new protocol
* *
* Revision 1.8 2004/09/03 22:35:37 justb * Revision 1.8 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.7 2004/08/15 16:00:15 justb * Revision 1.7 2004/08/15 16:00:15 justb
* enhancements to pull mode * enhancements to pull mode
* *
* Revision 1.6 2004/08/13 23:36:05 justb * Revision 1.6 2004/08/13 23:36:05 justb
* rewrite of Pullet into Pushlet "pull" mode * rewrite of Pullet into Pushlet "pull" mode
* *
* Revision 1.5 2004/08/12 13:18:54 justb * Revision 1.5 2004/08/12 13:18:54 justb
* cosmetic changes * cosmetic changes
* *
* Revision 1.4 2003/08/15 08:37:40 justb * Revision 1.4 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.3 2003/08/12 09:41:35 justb * Revision 1.3 2003/08/12 09:41:35 justb
* replace static initalizer with explicit init() * replace static initalizer with explicit init()
* *
* Revision 1.2 2003/05/18 16:15:08 justb * Revision 1.2 2003/05/18 16:15:08 justb
* support for XML encoded Events * support for XML encoded Events
* *
* Revision 1.1.1.1 2002/09/24 21:02:31 justb * Revision 1.1.1.1 2002/09/24 21:02:31 justb
* import to sourceforge * import to sourceforge
* *
* Revision 1.1.1.1 2002/09/20 22:48:17 justb * Revision 1.1.1.1 2002/09/20 22:48:17 justb
* import to SF * import to SF
* *
* Revision 1.1.1.1 2002/09/20 14:19:03 justb * Revision 1.1.1.1 2002/09/20 14:19:03 justb
* first import into SF * first import into SF
* *
* Revision 1.5 2002/04/15 20:42:41 just * Revision 1.5 2002/04/15 20:42:41 just
* reformatting and renaming GuardedQueue to EventQueue * reformatting and renaming GuardedQueue to EventQueue
* *
* Revision 1.4 2000/10/30 14:15:47 just * Revision 1.4 2000/10/30 14:15:47 just
* no message * no message
* *
* Revision 1.3 2000/08/31 08:26:54 just * Revision 1.3 2000/08/31 08:26:54 just
* Changed classloader that loads eventsources.properties to use EventSourceManager's classloader * Changed classloader that loads eventsources.properties to use EventSourceManager's classloader
* *
* Revision 1.2 2000/08/21 20:48:29 just * Revision 1.2 2000/08/21 20:48:29 just
* added CVS log and id tags plus copyrights * added CVS log and id tags plus copyrights
* *
* *
*/ */
@@ -1,99 +1,99 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.core; package nl.justobjects.pushlet.core;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
/** /**
* Implementation of ClientAdapter that sends Events as serialized objects. * Implementation of ClientAdapter that sends Events as serialized objects.
* <p/> * <p/>
* NOTE: You are discouraged to use this adapter, since it is Java-only * NOTE: You are discouraged to use this adapter, since it is Java-only
* and may have JVM-specific problems. Far better choice is to use XML * and may have JVM-specific problems. Far better choice is to use XML
* and the XMLAdapter. * and the XMLAdapter.
* *
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
* @version $Id: SerializedAdapter.java,v 1.4 2007/11/23 14:33:07 justb Exp $ * @version $Id: SerializedAdapter.java,v 1.4 2007/11/23 14:33:07 justb Exp $
*/ */
class SerializedAdapter implements ClientAdapter { class SerializedAdapter implements ClientAdapter {
private ObjectOutputStream out = null; private ObjectOutputStream out = null;
public static final String CONTENT_TYPE = "application/x-java-serialized-object"; public static final String CONTENT_TYPE = "application/x-java-serialized-object";
private HttpServletResponse servletRsp; private HttpServletResponse servletRsp;
/** /**
* Initialize. * Initialize.
*/ */
public SerializedAdapter(HttpServletResponse aServletResponse) { public SerializedAdapter(HttpServletResponse aServletResponse) {
servletRsp = aServletResponse; servletRsp = aServletResponse;
} }
public void start() throws IOException { public void start() throws IOException {
servletRsp.setContentType(CONTENT_TYPE); servletRsp.setContentType(CONTENT_TYPE);
// Use a serialized object output stream // Use a serialized object output stream
out = new ObjectOutputStream(servletRsp.getOutputStream()); out = new ObjectOutputStream(servletRsp.getOutputStream());
// Don't need this further // Don't need this further
servletRsp = null; servletRsp = null;
} }
/** /**
* Push Event to client. * Push Event to client.
*/ */
public void push(Event anEvent) throws IOException { public void push(Event anEvent) throws IOException {
out.writeObject(anEvent); out.writeObject(anEvent);
out.flush(); out.flush();
} }
public void stop() throws IOException { public void stop() throws IOException {
} }
} }
/* /*
* $Log: SerializedAdapter.java,v $ * $Log: SerializedAdapter.java,v $
* Revision 1.4 2007/11/23 14:33:07 justb * Revision 1.4 2007/11/23 14:33:07 justb
* core classes now configurable through factory * core classes now configurable through factory
* *
* Revision 1.3 2005/02/28 12:45:59 justb * Revision 1.3 2005/02/28 12:45:59 justb
* introduced Command class * introduced Command class
* *
* Revision 1.2 2005/02/21 11:50:46 justb * Revision 1.2 2005/02/21 11:50:46 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.1 2005/02/18 10:07:23 justb * Revision 1.1 2005/02/18 10:07:23 justb
* many renamings of classes (make names compact) * many renamings of classes (make names compact)
* *
* Revision 1.4 2004/09/03 22:35:37 justb * Revision 1.4 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.3 2003/08/15 08:37:40 justb * Revision 1.3 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.2 2003/05/18 16:13:48 justb * Revision 1.2 2003/05/18 16:13:48 justb
* fixed blocking for java.net.URL with HTTP/1.1 (JVMs > 1.1) * fixed blocking for java.net.URL with HTTP/1.1 (JVMs > 1.1)
* *
* Revision 1.1.1.1 2002/09/24 21:02:31 justb * Revision 1.1.1.1 2002/09/24 21:02:31 justb
* import to sourceforge * import to sourceforge
* *
* Revision 1.1.1.1 2002/09/20 22:48:18 justb * Revision 1.1.1.1 2002/09/20 22:48:18 justb
* import to SF * import to SF
* *
* Revision 1.1.1.1 2002/09/20 14:19:03 justb * Revision 1.1.1.1 2002/09/20 14:19:03 justb
* first import into SF * first import into SF
* *
* Revision 1.5 2002/04/15 20:42:41 just * Revision 1.5 2002/04/15 20:42:41 just
* reformatting and renaming GuardedQueue to EventQueue * reformatting and renaming GuardedQueue to EventQueue
* *
* Revision 1.4 2000/12/27 22:39:35 just * Revision 1.4 2000/12/27 22:39:35 just
* no message * no message
* *
* Revision 1.3 2000/08/21 20:48:29 just * Revision 1.3 2000/08/21 20:48:29 just
* added CVS log and id tags plus copyrights * added CVS log and id tags plus copyrights
* *
* *
*/ */
@@ -1,137 +1,137 @@
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl> // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org. // Distributable under LGPL license. See terms of license at gnu.org.
package nl.justobjects.pushlet.core; package nl.justobjects.pushlet.core;
import nl.justobjects.pushlet.util.Log; import nl.justobjects.pushlet.util.Log;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
/** /**
* ClientAdapter that sends Events as XML. * ClientAdapter that sends Events as XML.
* *
* @author Just van den Broecke - Just Objects &copy; * @author Just van den Broecke - Just Objects &copy;
* @version $Id: XMLAdapter.java,v 1.7 2007/11/09 13:15:35 justb Exp $ * @version $Id: XMLAdapter.java,v 1.7 2007/11/09 13:15:35 justb Exp $
*/ */
class XMLAdapter implements ClientAdapter { class XMLAdapter implements ClientAdapter {
/** /**
* Header for strict XML * Header for strict XML
*/ */
// public static final String XML_HEAD = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"; // public static final String XML_HEAD = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
private String contentType = "text/plain;charset=UTF-8"; private String contentType = "text/plain;charset=UTF-8";
private ServletOutputStream out = null; private ServletOutputStream out = null;
private HttpServletResponse servletRsp; private HttpServletResponse servletRsp;
private boolean strictXML; private boolean strictXML;
/** /**
* Initialize. * Initialize.
*/ */
public XMLAdapter(HttpServletResponse aServletResponse) { public XMLAdapter(HttpServletResponse aServletResponse) {
this(aServletResponse, false); this(aServletResponse, false);
} }
/** /**
* Initialize. * Initialize.
*/ */
public XMLAdapter(HttpServletResponse aServletResponse, boolean useStrictXML) { public XMLAdapter(HttpServletResponse aServletResponse, boolean useStrictXML) {
servletRsp = aServletResponse; servletRsp = aServletResponse;
// Strict XML implies returning a complete XML document // Strict XML implies returning a complete XML document
strictXML = useStrictXML; strictXML = useStrictXML;
if (strictXML) { if (strictXML) {
contentType = "text/xml;charset=UTF-8"; contentType = "text/xml;charset=UTF-8";
} }
} }
public void start() throws IOException { public void start() throws IOException {
// If content type is plain text // If content type is plain text
// then this is not a complete XML document, but rather // then this is not a complete XML document, but rather
// a stream of XML documents where each document is // a stream of XML documents where each document is
// an Event. In strict XML mode a complete document is returned. // an Event. In strict XML mode a complete document is returned.
servletRsp.setContentType(contentType); servletRsp.setContentType(contentType);
out = servletRsp.getOutputStream(); out = servletRsp.getOutputStream();
// Don't need this further // Don't need this further
servletRsp = null; servletRsp = null;
// Start XML document if strict XML mode // Start XML document if strict XML mode
if (strictXML) { if (strictXML) {
out.print("<pushlet>"); out.print("<pushlet>");
} }
} }
/** /**
* Force client to refresh the request. * Force client to refresh the request.
*/ */
public void push(Event anEvent) throws IOException { public void push(Event anEvent) throws IOException {
debug("event=" + anEvent); debug("event=" + anEvent);
// Send the event as XML to the client and flush. // Send the event as XML to the client and flush.
out.print(anEvent.toXML(strictXML)); out.print(anEvent.toXML(strictXML));
out.flush(); out.flush();
} }
/** /**
* No action. * No action.
*/ */
public void stop() throws IOException { public void stop() throws IOException {
// Close XML document if strict XML mode // Close XML document if strict XML mode
if (strictXML) { if (strictXML) {
out.print("</pushlet>"); out.print("</pushlet>");
out.flush(); out.flush();
} }
} }
private void debug(String s) { private void debug(String s) {
Log.debug("[XMLAdapter]" + s); Log.debug("[XMLAdapter]" + s);
} }
} }
/* /*
* $Log: XMLAdapter.java,v $ * $Log: XMLAdapter.java,v $
* Revision 1.7 2007/11/09 13:15:35 justb * Revision 1.7 2007/11/09 13:15:35 justb
* add charset=UTF-8 in returned HTTP content types * add charset=UTF-8 in returned HTTP content types
* *
* Revision 1.6 2006/05/15 11:52:53 justb * Revision 1.6 2006/05/15 11:52:53 justb
* updates mainly for AJAX client * updates mainly for AJAX client
* *
* Revision 1.5 2006/05/06 00:06:28 justb * Revision 1.5 2006/05/06 00:06:28 justb
* first rough version AJAX client * first rough version AJAX client
* *
* Revision 1.4 2005/05/06 19:44:00 justb * Revision 1.4 2005/05/06 19:44:00 justb
* added xml-strict format * added xml-strict format
* *
* Revision 1.3 2005/02/28 12:45:59 justb * Revision 1.3 2005/02/28 12:45:59 justb
* introduced Command class * introduced Command class
* *
* Revision 1.2 2005/02/21 11:50:47 justb * Revision 1.2 2005/02/21 11:50:47 justb
* ohase1 of refactoring Subscriber into Session/Controller/Subscriber * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
* *
* Revision 1.1 2005/02/18 10:07:23 justb * Revision 1.1 2005/02/18 10:07:23 justb
* many renamings of classes (make names compact) * many renamings of classes (make names compact)
* *
* Revision 1.7 2004/09/03 22:35:37 justb * Revision 1.7 2004/09/03 22:35:37 justb
* Almost complete rewrite, just checking in now * Almost complete rewrite, just checking in now
* *
* Revision 1.6 2004/03/10 14:01:55 justb * Revision 1.6 2004/03/10 14:01:55 justb
* formatting and *Subscriber refactoring * formatting and *Subscriber refactoring
* *
* Revision 1.5 2003/08/15 08:37:40 justb * Revision 1.5 2003/08/15 08:37:40 justb
* fix/add Copyright+LGPL file headers and footers * fix/add Copyright+LGPL file headers and footers
* *
* Revision 1.4 2003/08/13 14:00:00 justb * Revision 1.4 2003/08/13 14:00:00 justb
* some testing for applets; no real change * some testing for applets; no real change
* *
* Revision 1.3 2003/08/12 09:57:06 justb * Revision 1.3 2003/08/12 09:57:06 justb
* replaced all print statements to Log.*() calls * replaced all print statements to Log.*() calls
* *
* Revision 1.2 2003/05/19 21:56:29 justb * Revision 1.2 2003/05/19 21:56:29 justb
* various fixes for applet clients * various fixes for applet clients
* *
* Revision 1.1 2003/05/18 16:12:28 justb * Revision 1.1 2003/05/18 16:12:28 justb
* adding support for XML encoded Events * adding support for XML encoded Events
*/ */

Some files were not shown because too many files have changed in this diff Show More