what my problem is I have to give some details. If this message appears
two times it's because I had send it twice. One, a week ago, but
it didn't appear in the mailing list, and the second one this time.
I have made a OCF applet, and it functions well if I use it only one time
but when I reload the applet in the browser in the same session it doesn't
work well.
First, I'm going to make a short description of my problem and then a large
description.
//////////////////////////////////// SHORT DESCRITPION /////////////////////
I have a problem with the EventGenerator polling thread when reloading my applet.
- When I first initialized the applet it creates a new EventGenerator#701, and a new thread t =(Thread) #713 starting thread Thread -4.
- When I reload the applet in the browser, it first kills the polling thread Thread-4 and other threads in use, and begins initialiting the applet. The EventGenerator object is already created so it doesn't create a new one, it just use the one create (it's a singleton), but this object has a t variable holding the reference to the polling thread that it's not null t = (Thread) #713 , even if the thread (Thread-4) it's already dead. So when it checks if it's need to create a polling thread or not it just checks if the t varialble is null, if that the case it creates a new polling thread.
- MY PROBLEM is that I have t != null but the thread is dead, so it doesn't create a polling thread to check the terminals, and my applet is deaf to CARD_INSERTED or CARD_REMOVED events.
- �Anyone has had similar problems?�To which solution you arrive?
//////////////////////////////////// LARGE DESCRIPTION ///////////////////
I made a OCF applet, following the event driven programming model, where the
applet or some other class is notified when a card is inserted or removed.
To do that, the OCF provides the opencard.core.event.EventGenerator
singleton, which acts as a generator and multicaster for card terminal
events. It periodically polls the terminals and generates CARD_INSERTED or C
ARD_REMOVED events if it detects a card insertion or removal respectively.
To do this work, the EventGenerator creates a THREAD, which is going to run
in the background, as a daemon and periodically calls every registered
CardTerminal that implements the Pollable interface.
The source code, that creates the new thread is the following (extract from
EventGenerator source code):
Source Code from EventGenerator:
**********************************************************************
/** .
* Keep track of pollable terminals, used by CardTerminalRegistry
*
* @param p
* terminal that was added/removed to the registry
* @param terminalAdded true if a terminal was added. False,
* if a terminal was removed.
*/
public boolean updateTerminals(Pollable p, boolean terminalAdded) { synchronized(pollables) {
if (terminalAdded) {
ctracer.debug("updateTerminals", "new pollable Terminal = " + p);pollables.addElement(p);
try {
// avoid duplicate events for cards already present
// terminal should have current state, BEFORE any listener
// has a chance to register itsself
p.poll();
} catch (RuntimeException rte) {
// ignore runtime exceptions thrown by poll
ctracer.debug("run", rte);
} catch (CardTerminalException cte) {
ctracer.debug("run", cte);
} // start polling thread if not already started
if (t==null) {
t = new Thread(this);
t.setDaemon(true);
t.start();
}
return true;
} else {
ctracer.debug("updateTerminals", "remove pollable Terminal = " + p);
return pollables.removeElement(p);
}
}
}
***************************************************************************This "t" thread works quite well, responding to inserted and removed events,
if I have only initialized the applet one time, BUT MY PROBLEM ARISE when
the applet is reload by the browser.
When the browser do this, it kills this "t" thread, but it doesn't modified
or set to null the EventGenerator object already created, where the "t"
variable is not null. So when we arrive again to:
Source Code from EventGenerator:
************************************
// start polling thread if not already started
if (t==null) {
t = new Thread(this);
t.setDaemon(true);
t.start();
}
************************************Here, the "t" thread created when we initialized the applet, is dead, but
the t variable of the EventGenerator object is not null, so it doesn�t
create any new thread. So I end up without any thread in charge of polling
the card terminals for CARD_INSERTED or REMOVED events. That makes my class
or applet deaf to any inserted or remove events.
The only solution I've find, which I don't like because it needs to change
the OCF sources it's the following:
Source Code from my modified EventGenerator class:
*****************************************
// start polling thread if not already started
if (t==null) {
t = new Thread(this);
t.setDaemon(true);
t.start();
}else if(t.isAlive()==false) {
t = new Thread(this);
t.setDaemon(true);
t.start();
}
*****************************************Does anyone have had a similar problem? Did you arrive to a different solution?. If you can give me any advice or sugestion it will help me a lot.
Thank in advance for your help.
Angel
_________________________________________________________________
Charla con tus amigos en l�nea mediante MSN Messenger: http://messenger.latino.msn.com/
---
Visit the OpenCard web site at http://www.opencard.org/ for more information on OpenCard---binaries, source code, documents. This list is being archived at http://www.opencard.org/archive/opencard/
! To unsubscribe from the [EMAIL PROTECTED] mailing list send an email
! to
! [EMAIL PROTECTED]
! containing the word
! unsubscribe ! in the body.
