Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Periodic activity for duration of session?
Periodic activity for duration of session? [message #527640] Thu, 15 April 2010 21:03 Go to next message
Eclipse UserFriend
Originally posted by: djlynott.rockwellcollins.com

I'd like to apologize for posting yet another topic on asynchronous
event processing within RAP; however, even after reading the numerous
other threads in this newsgroup I am still left kind of confused on this
topic.

Within my RAP-based application, I would like to *reliably* record when
a user logs into my application and when they stop using the application
(i.e. explicitly log out, navigate to a new URL, or the session times out).

In previous attempts, I've tried registering for lifecycle event
notification which seemed to work inconsistently depending on how the
user left the application. It also appeared to contribute toward a
deadlock condition (which may have been a result of how I was using the
APIs).

I am about to embark on another method of periodically refreshing usage
and having a reclamation thread on the logging server that purges users
that have not been refreshed within the RAP application's session
inactivity timeout interval.

I just setup a timer task to periodically refresh the user via the
following code snippet:

<code>
// In ApplicationWorkbenchAdvisor::openWindows() method

Activator.getDefault().setStaleUserTimeout(
RWT.getRequest().getSession().getMaxInactiveInterval());
Activator.getDefault().addUser();

final Display display = PlatformUI.getWorkbench().getDisplay();
Runnable refreshUser = new Runnable() {
public void run() {
Activator.getDefault().addUser();
display.timerExec(REFRESH_INTERVAL, this);
}
};
display.timerExec(REFRESH_INTERVAL, refreshUser);
</code>

It appears that the code to "addUser()" only gets invoked if the user
interacts with the UI (which I didn't quite expect). This isn't all bad
(in my use-case) since it is acceptable to refresh the user when they
actually interact with the UI. Is there a better way of doing this by
hooking some event?

So where am I going with this? I'm just interested in some feedback on a
proven approach within RAP for doing what I'm trying to do -- either log
when a user enters/leaves my application or log when they interact with
my application. Any suggestion(s) would be greatly appreciated.

Thanks!
Re: Periodic activity for duration of session? [message #527720 is a reply to message #527640] Fri, 16 April 2010 08:30 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1313
Registered: July 2009
Senior Member

Hi Dave,

getting notified when a user leaves the page seems to be hard to
implement in a reliable way. Bug 284273 [1] contains a draft, but it
does not work in all browsers and has a problem with browser reload.

Another approach is sending pings from the client in a predefined
interval. A Javascript implementation is probably very simple.

If you are happy with tracing incoming requests, you can simply use a
PhaseListener.

Hope this helps,
Ralf


[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=284273

Dave Lynott wrote:
> I'd like to apologize for posting yet another topic on asynchronous
> event processing within RAP; however, even after reading the numerous
> other threads in this newsgroup I am still left kind of confused on this
> topic.
>
> Within my RAP-based application, I would like to *reliably* record when
> a user logs into my application and when they stop using the application
> (i.e. explicitly log out, navigate to a new URL, or the session times out).
>
> In previous attempts, I've tried registering for lifecycle event
> notification which seemed to work inconsistently depending on how the
> user left the application. It also appeared to contribute toward a
> deadlock condition (which may have been a result of how I was using the
> APIs).
>
> I am about to embark on another method of periodically refreshing usage
> and having a reclamation thread on the logging server that purges users
> that have not been refreshed within the RAP application's session
> inactivity timeout interval.
>
> I just setup a timer task to periodically refresh the user via the
> following code snippet:
>
> <code>
> // In ApplicationWorkbenchAdvisor::openWindows() method
>
> Activator.getDefault().setStaleUserTimeout(
> RWT.getRequest().getSession().getMaxInactiveInterval());
> Activator.getDefault().addUser();
>
> final Display display = PlatformUI.getWorkbench().getDisplay();
> Runnable refreshUser = new Runnable() {
> public void run() {
> Activator.getDefault().addUser();
> display.timerExec(REFRESH_INTERVAL, this);
> }
> };
> display.timerExec(REFRESH_INTERVAL, refreshUser);
> </code>
>
> It appears that the code to "addUser()" only gets invoked if the user
> interacts with the UI (which I didn't quite expect). This isn't all bad
> (in my use-case) since it is acceptable to refresh the user when they
> actually interact with the UI. Is there a better way of doing this by
> hooking some event?
>
> So where am I going with this? I'm just interested in some feedback on a
> proven approach within RAP for doing what I'm trying to do -- either log
> when a user enters/leaves my application or log when they interact with
> my application. Any suggestion(s) would be greatly appreciated.
>
> Thanks!
Re: Periodic activity for duration of session? [message #527786 is a reply to message #527720] Fri, 16 April 2010 13:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: djlynott.rockwellcollins.com

After I wrote this yesterday, I happened upon the phase listener
stuff... I think I'll try that today and see how it works. Which phase
would you recommend when performing this activity?

BTW: Thanks for the response!

On 4/16/2010 3:30 AM, Ralf Sternberg wrote:
> Hi Dave,
>
> getting notified when a user leaves the page seems to be hard to
> implement in a reliable way. Bug 284273 [1] contains a draft, but it
> does not work in all browsers and has a problem with browser reload.
>
> Another approach is sending pings from the client in a predefined
> interval. A Javascript implementation is probably very simple.
>
> If you are happy with tracing incoming requests, you can simply use a
> PhaseListener.
>
> Hope this helps,
> Ralf
Re: Periodic activity for duration of session? [message #527890 is a reply to message #527786] Fri, 16 April 2010 19:20 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1313
Registered: July 2009
Senior Member

Hi Dave,

for this case the phase doesn't really matter. Hook before PrepareUIRoot
if you want to be notified before any request processing or after Render
to be notified last.

Best, Ralf

Dave Lynott wrote:
> After I wrote this yesterday, I happened upon the phase listener
> stuff... I think I'll try that today and see how it works. Which phase
> would you recommend when performing this activity?
>
> BTW: Thanks for the response!
>
> On 4/16/2010 3:30 AM, Ralf Sternberg wrote:
>> Hi Dave,
>>
>> getting notified when a user leaves the page seems to be hard to
>> implement in a reliable way. Bug 284273 [1] contains a draft, but it
>> does not work in all browsers and has a problem with browser reload.
>>
>> Another approach is sending pings from the client in a predefined
>> interval. A Javascript implementation is probably very simple.
>>
>> If you are happy with tracing incoming requests, you can simply use a
>> PhaseListener.
>>
>> Hope this helps,
>> Ralf
Re: Periodic activity for duration of session? [message #527906 is a reply to message #527890] Fri, 16 April 2010 21:11 Go to previous message
Eclipse UserFriend
Originally posted by: djlynott.rockwellcollins.com

I think I have things working with the following code:

<code>
// Code from ApplicationWorkbenchAdvisor::openWindows()

Activator.getDefault().setStaleUserTimeout(
RWT.getRequest().getSession().getMaxInactiveInterval());
Activator.getDefault().addUser();

// Refresh user on phase changes... which should occur
// on any interaction with the reporting application.
final PhaseListener listener = new PhaseListener() {
private final Display display = Display.getCurrent();
private static final long serialVersionUID = 1L;
private Date lastRefresh = new Date();
private static final long REFRESH_INTERVAL_IN_MS = 60000;

@Override
public void afterPhase(PhaseEvent event) { }

@Override
public void beforePhase(PhaseEvent event) {
if ((display == Display.getCurrent()) &&
(event.getPhaseId() == PhaseId.PROCESS_ACTION)) {
Date now = new Date();
if ((now.getTime() - lastRefresh.getTime())
> REFRESH_INTERVAL_IN_MS) {
Activator.getDefault().addUser();
lastRefresh = now;
}
}
}

@Override
public PhaseId getPhaseId() {
return PhaseId.PROCESS_ACTION;
}
};
RWT.getLifeCycle().addPhaseListener(listener);

// Unregister user and remove phase listener on session cleanup...
Display.getCurrent().disposeExec(new Runnable() {
@Override
public void run() {
Activator.getDefault().removeUser();
RWT.getLifeCycle().removePhaseListener(listener);
}
});
</code>

I was a bit surprised that the phase listeners were not session scope. I
hope the following code cleans these objects up effectively.
Previous Topic:RAP and ThreadLocals
Next Topic:Is there a tool or plugin for RAP to trace memory use
Goto Forum:
  


Current Time: Wed Oct 09 19:54:33 GMT 2024

Powered by FUDForum. Page generated in 0.04020 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top