[Building Sakai] Post login event listener

Jim Eng jimeng at umich.edu
Mon Aug 8 08:03:26 PDT 2011


Sorry.  I didn't complete that example.  Here's a better version of it:

	public void update(Observable arg0, Object obj) {
		if(obj != null && obj instanceof Event) {
			Event event = (Event) obj;
			if(ContentHostingService.EVENT_RESOURCE_ADD.equals(event.getEvent())) {
				// do something				
			}
		}
		
	}

The event.getEvent() method returns a unique string identifier that tells us which kind of event it is.

Jim

On Aug 8, 2011, at 11:01 AM, Jim Eng wrote:

> One more note.  Here's a little sample of a fictional event listener's update() method:
> 
> 	public void update(Observable arg0, Object obj) {
> 		if(obj != null && obj instanceof Event) {
> 			Event event = (Event) obj;
> 			if(ContentHostingService.EVENT_RESOURCE_ADD.equals()) {
> 				// do something				
> 			}
> 		}
> 		
> 	}
> 
> We can use event.getResource() to get sakai's internal reference string from the event.  That uniquely identifies the entity within sakai.  We can use it to retrieve the entity, if we need it.
> 
> Jim
> 
> 
> On Aug 8, 2011, at 10:22 AM, Jim Eng wrote:
> 
>> Hi David,
>> 
>> Actually, the interface you implement is java.util.Observer:
>> 
>> 	http://download.oracle.com/javase/6/docs/api/index.html?overview-summary.html
>> 
>> You register your Observer with EventTrackingService:
>> 
>> 	http://source.sakaiproject.org/release/kernel/1.0.13/apidocs/index.html
>> 
>> You can register an Observer as a "local" observer, which means that your update() method will be called only on the server where the event occurred.  Or you can register an Observer to listen to all events regardless of where in the cluster they occur.  
>> 
>> Your update() method will get two params.  The second will be an event object. You should very very quickly check whether you are interested in the event.  If not, you should return ASAP.  Of course, you should return ASAP anyway. 
>> 
>> HTH.
>> 
>> Jim    
>> 
>> On Aug 8, 2011, at 10:09 AM, David Wafula wrote:
>> 
>>> Could a kind soul point me to where i could get started with event listeners..i am needing to write a login listener. I was imagining an interface somewhere that i could implement like below:
>>> 
>>> 
>>> interface LoginListener{
>>> 
>>> public void loginSuccessful();
>>> 
>>> public void loginFail();
>>> }
>>> 
>>> -- 
>>> David Wafula
>>> _______________________________________________
>>> sakai-dev mailing list
>>> sakai-dev at collab.sakaiproject.org
>>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>> 
>>> TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of "unsubscribe"
>> 
>> _______________________________________________
>> sakai-dev mailing list
>> sakai-dev at collab.sakaiproject.org
>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>> 
>> TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of "unsubscribe"
>> 
>> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20110808/6fbcae15/attachment.html 


More information about the sakai-dev mailing list