[jboss-user] [EJB3] - Re: @Server, xmbean and attribute persistence?
John Franey
do-not-reply at jboss.com
Wed Nov 17 16:10:22 EST 2010
John Franey [http://community.jboss.org/people/jjfraney] created the discussion
"Re: @Server, xmbean and attribute persistence?"
To view the discussion, visit: http://community.jboss.org/message/571690#571690
--------------------------------------------------------------
I did this to resolve my requirement:
Implement an interceptor on my service. It uses the AttributePersistenceService directly to save attributes. Implement the 'start' lifecycle method to load attributes from the AttributePersistenceService.
{code}
@Depends("jboss:service=AttributePersistenceService")
private AttributePersistenceServiceMBean attributePersistenceService;
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
Object result = context.proceed();
if(context.getMethod().getName().startsWith("set")) {
saveAttributes();
}
return result;
}
public void start() throws Exception {
loadAttributes();
}
private void saveAttributes() throws Exception {
AttributePersistenceManager manager = getAttributePersistenceManager();
if(manager != null) {
AttributeList attrs = new AttributeList();
attrs.add(new Attribute("syncInterval", syncInterval));
LOGGER.debug("saving attributes: {}", attrs);
manager.store(ATTRIBUTE_KEY, attrs);
}
}
private void loadAttributes() throws Exception {
AttributePersistenceManager manager = getAttributePersistenceManager();
if(manager != null) {
AttributeList attrs = manager.load(ATTRIBUTE_KEY);
for(Attribute attribute: attrs.asList()) {
if("syncInterval".equals(attribute.getName())) {
this.syncInterval = ((Long)attribute.getValue()).longValue();
}
}
}
}
private AttributePersistenceManager getAttributePersistenceManager() {
AttributePersistenceManager result = null;
if(attributePersistenceService != null) {
result = attributePersistenceService.apmCreate();
}
return result;
}
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
Object result = context.proceed();
if(context.getMethod().getName().startsWith("set")) {
saveAttributes();
}
return result;
}
public void start() throws Exception {
loadAttributes();
}
private void saveAttributes() throws Exception {
AttributePersistenceManager manager = getAttributePersistenceManager();
if(manager != null) {
AttributeList attrs = new AttributeList();
attrs.add(new Attribute("syncInterval", syncInterval));
LOGGER.debug("saving attributes: {}", attrs);
manager.store(ATTRIBUTE_KEY, attrs);
}
}
private void loadAttributes() throws Exception {
AttributePersistenceManager manager = getAttributePersistenceManager();
if(manager != null) {
AttributeList attrs = manager.load(ATTRIBUTE_KEY);
for(Attribute attribute: attrs.asList()) {
if("syncInterval".equals(attribute.getName())) {
this.syncInterval = ((Long)attribute.getValue()).longValue();
}
}
}
}
private AttributePersistenceManager getAttributePersistenceManager() {
AttributePersistenceManager result = null;
if(attributePersistenceService != null) {
result = attributePersistenceService.apmCreate();
}
return result;
}
{code}
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/571690#571690]
Start a new discussion in EJB3 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20101117/6115b7e4/attachment.html
More information about the jboss-user
mailing list