-
1. Re: @Server, xmbean and attribute persistence?
jjfraney Nov 17, 2010 11:03 AM (in response to jjfraney)Further debugging tells me the interceptors are not being called when the attribute is stored. I don't see a call to PersistenceInterceptor.invoke.
I added these lines to my mbean descriptor. No go.
<descriptors><interceptors><interceptor code="org.jboss.mx.interceptor.PersistenceInterceptor2" /><interceptor code="org.jboss.mx.interceptor.ModelMBeanInterceptor" /><interceptor code="org.jboss.mx.interceptor.ObjectReferenceInterceptor" /></interceptors><persistence persistPolicy="OnUpdate" /><persistence-managervalue="org.jboss.mx.persistence.JunkDelegatingPersistenceManager" /></descriptors><descriptors>
<interceptors>
<interceptor code="org.jboss.mx.interceptor.PersistenceInterceptor2" />
<interceptor code="org.jboss.mx.interceptor.ModelMBeanInterceptor" />
<interceptor code="org.jboss.mx.interceptor.ObjectReferenceInterceptor" />
</interceptors>
<persistence persistPolicy="OnUpdate" />
<persistence-manager
value="org.jboss.mx.persistence.JunkDelegatingPersistenceManager" />
</descriptors>
Still, I'm expecting these to get called. Foolish?
Thanks,
John
-
2. Re: @Server, xmbean and attribute persistence?
jjfraney Nov 17, 2010 4:10 PM (in response to jjfraney)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;
@AroundInvokepublic 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}