Context specific Outjection modes in JBoss Seam
There are 7 types of contexts available in JBoss Seam. In order to outject (make an instantiated/ populated object available to other components participating in the same context) for a particular scope, say CONVERSATION, there are at least 2 ways of outjecting an instance as follows:
1) Declaratively : This could be used when there are component boundaries clearly demarcated and the instance needs to available for a longer running conversation. An example snippet is given below:
@Name("producer")
public class Producer
{ @Out(scope=ScopeType.CONVERSATION)
private QueueFeed feed;
//methods to produce and populate the feed
@Begin public void doStart(){}
@End public void close(){}
}
@Name("consumer")
public class Consumer
{ @In private QueueFeed feed;
//methods to consume and cleanup the feed
}
2) Programmaticaly : This approach is used when one would want place the instance in the already established context, and other seam components just reference the instance and used as given below:
@Name("producer")
public class Producer
{ public void produceIntermediate()
{ QueueFeed queueFeed;
//populate queueFeed
Contexts.getConversationContext().set("queueFeed", queueFeed);
}
}
@Name("consumer")
public class Consumer
{ public void consumeIntermediate()
{ QueueFeed queueFeed = (QueueFeed) ( Contexts.getConversationContext().get("queueFeed",));
}
}
This way one can manage scopes effectively with regard to instance usage across participating components