User: jules_gosnell
Date: 02/01/13 05:26:46
Added: jetty/src/main/org/jboss/jetty/util
AbstractTimeOutManager.java
NaiveTimeOutManager.java
Log:
split src into dirs
check in latest DistributedSession code
Revision Changes Path
1.1
contrib/jetty/src/main/org/jboss/jetty/util/AbstractTimeOutManager.java
Index: AbstractTimeOutManager.java
===================================================================
/*
* jBoss, the OpenSource EJB server
*
* Distributable under GPL license.
* See terms of license at gnu.org.
*/
// $Id: AbstractTimeOutManager.java,v 1.1 2002/01/13 13:26:46 jules_gosnell Exp $
//------------------------------------------------------------------------------
package org.jboss.jetty.util;
//------------------------------------------------------------------------------
public interface
AbstractTimeOutManager
{
public void register(Object object, long now, long timeRemaining);
public void reregister(Object object, long now, long timeRemaining);
public void deregister(Object object);
public void start();
public void stop();
public interface
TimeOutNotifier
{
public void timeOut(Object object);
}
}
1.1
contrib/jetty/src/main/org/jboss/jetty/util/NaiveTimeOutManager.java
Index: NaiveTimeOutManager.java
===================================================================
/*
* jBoss, the OpenSource EJB server
*
* Distributable under GPL license.
* See terms of license at gnu.org.
*/
// $Id: NaiveTimeOutManager.java,v 1.1 2002/01/13 13:26:46 jules_gosnell Exp $
//------------------------------------------------------------------------------
package org.jboss.jetty.util;
//------------------------------------------------------------------------------
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
//------------------------------------------------------------------------------
public class
NaiveTimeOutManager
implements AbstractTimeOutManager
{
final List _entries=new LinkedList();
final long _interval;
final TimeOutNotifier _notifier;
public
NaiveTimeOutManager(long interval, TimeOutNotifier notifier)
{
_interval=interval;
_notifier=notifier;
}
class Entry
{
final long _timeRegistered;
final long _timeRemaining;
final Object _object;
Entry(long timeRegistered, long timeRemaining, Object object)
{
_timeRegistered=timeRegistered;
_timeRemaining=timeRemaining;
_object=object;
}
long
getTimeRemaining(long now)
{
long timeSinceRegistered=now-_timeRegistered;
return _timeRemaining-timeSinceRegistered;
}
void
timeOut()
{
_notifier.timeOut(_object);
}
}
public synchronized void
register(Object object, long timeRegistered, long timeRemaining)
{
if (timeRemaining<0)
return; // never timeout
Entry entry=new Entry(timeRegistered, timeRemaining, object);
synchronized (_entries) {
_entries.add(entry);
}
}
public synchronized void
reregister(Object object, long timeRegistered, long timeRemaining)
{
// could be optimised - but this is simpler for the moment...
deregister(object);
register(object, timeRegistered, timeRemaining);
}
public synchronized void
deregister(Object object)
{
Entry p=find(object);
synchronized (_entries) {
_entries.remove(p);
}
}
// utils...
Entry
find(Object object)
{
Iterator i=_entries.iterator();
while (i.hasNext())
{
Entry p=(Entry)i.next();
if (p._object==object)
return p;
}
return null;
}
volatile boolean _loop=true;
public synchronized void
start()
{
new Thread() {
public void
run()
{
while (_loop)
{
try
{
sleep(_interval);
sweep();
}
catch (InterruptedException e)
{}
}
}
}.start();
}
public synchronized void
stop()
{
_loop=false;
}
void
sweep()
{
List copy;
synchronized (_entries) {copy=new LinkedList(_entries);};
long now=System.currentTimeMillis();
Iterator i=copy.iterator();
while (i.hasNext())
{
Entry p=(Entry)i.next();
if (p.getTimeRemaining(now)<1)
{
try
{
p.timeOut();
}
catch (Exception e)
{
System.err.println("Problem notifying: "+p._object);
e.printStackTrace(); // TODO
}
}
}
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development