{
invoker.invoke(setMethod, new Object[] { value }, new String[] { invocation.getAttributeType() });
}
catch (Throwable t)
{
throw new InvocationException(t);
}
}
// get the currency time limit value
String timeLimit = (String)d.getFieldValue(CURRENCY_TIME_LIMIT);
long limit = (timeLimit == null) ? 0 : Long.parseLong(timeLimit);
// if caching is not disabled, update the descriptor fields
if (limit != 0)
{
d.setField(VALUE, value);
d.setField(LAST_UPDATED_TIME_STAMP, "" + System.currentTimeMillis() / 1000);
invocation.setDescriptor(d);
}
// send notification
try
{
((ModelMBeanInvoker)invoker).sendAttributeChangeNotification(
new Attribute(invocation.getName(), oldValue),
new Attribute(invocation.getName(), value)
);
}
catch (MBeanException e)
{
throw new InvocationException(e, "attribute change notification error");
}
}
else if (invocation.getType().equals(Invocation.OP_GETATTRIBUTE))
{
// get the attribute's descriptor
String getMethod = (String)d.getFieldValue(GET_METHOD);
if (getMethod != null)
{
String timeLimit = (String)d.getFieldValue(CURRENCY_TIME_LIMIT);
long limit = (timeLimit == null) ? 0 : Long.parseLong(timeLimit);
if (limit == -1)
return d.getFieldValue(VALUE);
// if >0 caching is enabled
if (limit > 0)
{
String timeStamp = (String)d.getFieldValue(LAST_UPDATED_TIME_STAMP);
long lastUpdate = (timeStamp == null) ? 0 : Long.parseLong(timeStamp);
// if the value hasn't gone stale, return from the descriptor
if (System.currentTimeMillis() < lastUpdate * 1000 + limit * 1000)
return d.getFieldValue(VALUE);
}
// we got here means either stale value in descriptior, or zero time limit
MBeanInvoker invoker = invocation.getInvoker();
Object value = null;
try
{
value = invoker.invoke(getMethod, new Object[0], new String[0]);
}
catch (Throwable t)
{
throw new InvocationException(t);
}
// update the descriptor
d.setField(VALUE, value);
d.setField(LAST_UPDATED_TIME_STAMP, "" + System.currentTimeMillis() / 1000);