Java Doc for TodoSubscription.java in  » Science » Cougaar12_4 » org » cougaar » core » blackboard » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.core.blackboard 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.cougaar.core.blackboard.Subscription
      org.cougaar.core.blackboard.TodoSubscription

TodoSubscription
public class TodoSubscription extends Subscription (Code)
A subscription that queues objects, such as Alarms and other non-blackboard callbacks, for processing in the plugin's "execute()" thread.

TodoSubscriptions are typically used for Alarm callbacks, for example:

 public class MyPlugin extends ComponentPlugin {
 private TodoSubscription expiredAlarms;
 protected void setupSubscriptions() {
 expiredAlarms = (TodoSubscription) 
 blackboard.subscribe(new TodoSubscription("x"));
 // wake up in 10 seconds
 getAlarmService().addRealTimeAlarm(
 new MyAlarm(System.currentTimeMillis() + 10000));
 }
 protected void execute() {
 if (expiredAlarms.hasChanged()) {
 System.out.println("Due alarms: "+expiredAlarms.getAddedCollection());
 }
 }
 private class MyAlarm extends AlarmBase {
 // optionally add fields here, e.g. data or a Runnable
 public MyAlarm(long time) { super(time); }
 // don't do work in the "onExpire()" method, since it's the
 // AlarmService's callback thread.  Instead, put this alarm on our
 // "todo" queue, which will asynchronously call our "execute()".
 public void onExpire() { expiredAlarms.add(this); }
 }
 }
 

This is analogous to Swing's "invokeLater" pattern, for example:

 SwingUtilities.invokeLater(new Runnable() {
 public void run() { ... }
 });
 
where the Runnable is put on a queue and will be "run()" in the Swing thread.



Constructor Summary
public  TodoSubscription(String name)
     Create a TodoSubscription with the given non-null, unique name.

The name can be an arbitrary, non-null name, so long as the set of names is unique within each plugin instance.

We need the name to support agent mobility and persistence in cases where a plugin has more than one TodoSubscription.

For example, say a plugin has two TodoSubscriptions:

 protected void setupSubscriptions() {
 alpha = (TodoSubscription) blackboard.subscribe(new TodoSubscription("x"));
 beta = (TodoSubscription) blackboard.subscribe(new TodoSubscription("y"));
 }
 
and we persist just after calling:
 alpha.add(new Foo(1234));
 
but before we've had a chance to "execute()".

Method Summary
public  voidadd(Object o)
     Add an object to the queue of pending objects that will be visible in the next blackboard transaction's TodoSubscription.getAddedCollection , and request an asynchronous plugin "execute()" cycle.
public  voidaddAll(Collection c)
    
public  booleanapply(Envelope envelope)
    
protected  CollectioncreateCollection()
     Create the backing collection for reuse in TodoSubscription.getAddedCollection , which defaults to an ArrayList.
public  voidfill(Envelope envelope)
    
public  CollectiongetAddedCollection()
     a possibly empty collection of objects that have beenadded since the last transaction.
public  EnumerationgetAddedList()
    
protected  voidprivateAdd(Object o, boolean isVisible)
    
protected  voidprivateChange(Object o, List changes, boolean isVisible)
    
protected  voidprivateRemove(Object o, boolean isVisible)
    
protected  voidresetChanges()
    


Constructor Detail
TodoSubscription
public TodoSubscription(String name)(Code)
Create a TodoSubscription with the given non-null, unique name.

The name can be an arbitrary, non-null name, so long as the set of names is unique within each plugin instance.

We need the name to support agent mobility and persistence in cases where a plugin has more than one TodoSubscription.

For example, say a plugin has two TodoSubscriptions:

 protected void setupSubscriptions() {
 alpha = (TodoSubscription) blackboard.subscribe(new TodoSubscription("x"));
 beta = (TodoSubscription) blackboard.subscribe(new TodoSubscription("y"));
 }
 
and we persist just after calling:
 alpha.add(new Foo(1234));
 
but before we've had a chance to "execute()". This pending object will be persisted as a pending "inbox envelope" and rehydrated when we restart the agent. Our "setupSubscriptions()" will be called again, and we want to make sure that the object is put on the "alpha" TodoSubscription.getAddedCollection and not on "beta".

We need the name to match the rehydrated "inbox envelope" with the above

 ... new TodoSubscription("x") ...
 
since we persist the envelopes, not the subscription instances. Besides, the "new TodoSubscription" is a brand new subscription instance, so without the name, we'd have no way to figure out that these two instances represent the same "todo".




Method Detail
add
public void add(Object o)(Code)
Add an object to the queue of pending objects that will be visible in the next blackboard transaction's TodoSubscription.getAddedCollection , and request an asynchronous plugin "execute()" cycle.

This is analogous to a blackboard "publishAdd", except that the object is only visible to this subscription and will not be persisted.
Parameters:
  o - the object to put on the queue, which can be any non-null object(either data or a Runnable)




addAll
public void addAll(Collection c)(Code)

See Also:   TodoSubscription.add(Object)
See Also:   



apply
public boolean apply(Envelope envelope)(Code)
For infrastructure use only



createCollection
protected Collection createCollection()(Code)
Create the backing collection for reuse in TodoSubscription.getAddedCollection , which defaults to an ArrayList.

Another useful option is a LinkedHashSet, which filters out duplicates.




fill
public void fill(Envelope envelope)(Code)
For infrastructure use only



getAddedCollection
public Collection getAddedCollection()(Code)
a possibly empty collection of objects that have beenadded since the last transaction. Will not return null.



getAddedList
public Enumeration getAddedList()(Code)
an enumeration of the objects that have been addedsince the last transaction.



privateAdd
protected void privateAdd(Object o, boolean isVisible)(Code)



privateChange
protected void privateChange(Object o, List changes, boolean isVisible)(Code)



privateRemove
protected void privateRemove(Object o, boolean isVisible)(Code)



resetChanges
protected void resetChanges()(Code)



Fields inherited from org.cougaar.core.blackboard.Subscription
protected boolean myHasChanged(Code)(Java Doc)
final protected UnaryPredicate predicate(Code)(Java Doc)
protected Subscriber subscriber(Code)(Java Doc)

Methods inherited from org.cougaar.core.blackboard.Subscription
public boolean apply(Envelope envelope)(Code)(Java Doc)
final protected void checkTransactionOK(String s)(Code)(Java Doc)
boolean conditionalAdd(Object o, boolean isVisible)(Code)(Java Doc)
boolean conditionalChange(Object o, List changes, boolean isVisible)(Code)(Java Doc)
boolean conditionalRemove(Object o, boolean isVisible)(Code)(Java Doc)
public void fill(Envelope envelope)(Code)(Java Doc)
public String getName()(Code)(Java Doc)
final public Subscriber getSubscriber()(Code)(Java Doc)
final public boolean hasChanged()(Code)(Java Doc)
abstract protected void privateAdd(Object o, boolean isVisible)(Code)(Java Doc)
final protected boolean privateApply(Envelope envelope)(Code)(Java Doc)
abstract protected void privateChange(Object o, List changes, boolean isVisible)(Code)(Java Doc)
abstract protected void privateRemove(Object o, boolean isVisible)(Code)(Java Doc)
protected void resetChanges()(Code)(Java Doc)
final protected void setChanged(boolean changed)(Code)(Java Doc)
final void setIsInitialized()(Code)(Java Doc)
final void setSubscriber(Subscriber s)(Code)(Java Doc)
final protected void subscriberSignalExternalActivity()(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.