[jboss-user] [JBoss AOP] - Problem with locks
andarinneo
do-not-reply at jboss.com
Tue Sep 9 15:51:40 EDT 2008
hi i'm a newbie, and i'm trying to use jboss cache but when i eliminate everything from the cache, and then try to put a new object in it, a timeout exception happens.
the code is as follows:
private void initCache( ) throws UnexpectedException {
// 1. DDBB access
ArrayList workingModulesCacheable = getWorkingModuleSensors( );
ArrayList alarmsToValidateCacheable = getAlarmsToValidate( );
// 2. Store this information in the CACHE.
// JBoss CACHE functionality
server = MBeanServerLocator.locateJBoss( );
try {
cache = ( PojoCacheMBean ) MBeanProxyExt.create( PojoCacheMBean.class,
"jboss.cache:service=DesaladoraPojoCache",
server );
cache.putObject( "/stpd/adquisition/workingModules", workingModulesCacheable );
cache.putObject( "/stpd/alarms/alarmswatchdog/alarmsToValidate", alarmsToValidateCacheable );
}
catch ( MalformedObjectNameException e ) {
UnexpectedException ue = new UnexpectedException( e.getMessage( ), e );
logger.error("[" + ue.getClass().getName() + "]: " + ue.getMessage(), ue);
}
catch ( CacheException e1 ) {
UnexpectedException ue = new UnexpectedException( e1.getMessage( ), e1 );
logger.error("[" + ue.getClass().getName() + "]: " + ue.getMessage(), ue);
}
}
private void removeCache( ) throws Exception {
server = MBeanServerLocator.locateJBoss( );
try {
cache = ( PojoCacheMBean ) MBeanProxyExt.create( PojoCacheMBean.class,
"jboss.cache:service=DesaladoraPojoCache",
server );
cache.remove( "/" );
}
catch ( MalformedObjectNameException e ) {
UnexpectedException ue = new UnexpectedException( e.getMessage( ), e );
logger.error("[" + ue.getClass().getName() + "]: " + ue.getMessage(), ue);
}
catch ( CacheException e1 ) {
UnexpectedException ue = new UnexpectedException( e1.getMessage( ), e1 );
logger.error("[" + ue.getClass().getName() + "]: " + ue.getMessage(), ue);
}
}
this are the two functions i use to control the cache, the problem happens in this line:
cache.putObject( "/stpd/adquisition/workingModules", workingModulesCacheable );
i know that my request is very generic, so if the answer isn't known i would appreciatte guidance on where to rely, what to read, etc... because the api's documentation hasn't been much of a help for me
thank you in advance, if further information is required please tell me, another thing after the timeout i try again and it doesn't let me because it tells me that the lock couldn't be acquired, i think this is consecuence of the first problem, please confirm.
i'm using the -> jboss-cache-jdk50.jar
this is the complete file:
package stpd.component.coodinator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import org.apache.log4j.Logger;
import org.jboss.cache.CacheException;
import org.jboss.cache.aop.PojoCacheMBean;
import org.jboss.mx.util.MBeanProxyExt;
import org.jboss.mx.util.MBeanServerLocator;
import stpd.common.dto.alarms.AlarmCatalogDTO;
import stpd.common.dto.sensors.ConnectedSensorFullDTO;
import stpd.common.dto.sensors.DAHModuleDTO;
import stpd.common.dto.sms.PhoneNumberDTO;
import stpd.common.dto.sms.SmsCatalogFullDataDTO;
import stpd.common.exceptions.UnexpectedException;
import stpd.common.util.enums.plant.State;
import stpd.component.cache.data.AlarmData;
import stpd.component.cache.data.WorkingModuleSensors;
import stpd.component.common.data.alarms.ActiveAlarm;
import stpd.component.common.data.alarms.AlarmUtils;
import stpd.component.common.data.alarms.ValidatedAlarm;
import stpd.component.interfaces.adquisition.DataReadingsTimer;
import stpd.component.interfaces.alarms.AlarmManagerService;
import stpd.component.interfaces.coordinator.Coordinator;
import stpd.component.interfaces.sensors.SensorManagerService;
import stpd.component.interfaces.sms.SmsManagerService;
@Stateless
@Local(Coordinator.class)
public class CoordinatorBean implements Coordinator {
private String infoTimer;
private long milisg;
static final Logger logger = Logger.getLogger( "stpd.component.coordinator" );
@EJB
private SensorManagerService sensorMs;
@EJB
private AlarmManagerService aMs;
@EJB
private SmsManagerService smsMs;
@EJB
private DataReadingsTimer dataReadingsTimer;
private MBeanServer server;
private PojoCacheMBean cache;
public CoordinatorBean( ) {
super( );
infoTimer = new String( "system_adquisition_timer" );
milisg = 10000;
}
@SuppressWarnings("unchecked")
public ActiveAlarm getActiveAlarms() throws UnexpectedException {
ActiveAlarm activeAlarms = new ActiveAlarm("Lista de alarmas monitorizadas y que se encuentran activas");
ArrayList sensors = null;
try {
server = MBeanServerLocator.locateJBoss( );
cache = ( PojoCacheMBean ) MBeanProxyExt.create( PojoCacheMBean.class,
"jboss.cache:service=DesaladoraPojoCache",
server );
sensors = ( ArrayList ) cache.getObject( "/stpd/adquisition/workingModules" );
if ( sensors != null ) {
// se introducen todas al principio y posteriormente se eliminan las que no estan activas
activeAlarms = ( ActiveAlarm ) cache.getObject( "/stpd/alarms/alarmswatchdog/lastMonitoredAlarms" );
if ( activeAlarms != null){
logger.debug( "GETTING ALARMS" );
Collection alarms = activeAlarms.getAlarmList( ).values( );
for ( ValidatedAlarm alarm : alarms ) {
if ( !alarm.getCurrentlyActive( ) ) {
activeAlarms.getAlarmList( ).remove( alarm.getIdAlarm( ) );
}
}
}
}
}
catch ( CacheException ce ) {
UnexpectedException ue = new UnexpectedException( ce.getMessage( ), ce );
logger.error("[" + ue.getClass().getName() + "]: " + ue.getMessage(), ue);
}
catch ( MalformedObjectNameException e ) {
UnexpectedException ue = new UnexpectedException( e.getMessage( ), e );
logger.error("[" + ue.getClass().getName() + "]: " + ue.getMessage(), ue);
}
return activeAlarms;
}
/**
* Start the System and subprocess. Steps: 1. Start System Timer 2. Init Cache Data
* @throws UnexpectedException
*/
public void startSystem( ) throws UnexpectedException {
logger.debug( "Entering 'startSystem' to START timer [" + infoTimer + "]" );
// 1. Start System Timer
dataReadingsTimer.scheduleDataAdquisitionTimer( infoTimer, milisg );
// 2. Init Cache Data
initCache( );
}
/**
* Stop the System and subprocess. Steps: 1. Stop System Timer 2. Remove any stored Cache
* Data
*/
public void stopSystem( ) throws Exception {
logger.debug( "Entering 'stopSystem' to STOP timer and remove any data from de cache" );
// 1. Stop System Timer
dataReadingsTimer.stopTimer( infoTimer );
// 2. Remove any stored Cache Data
removeCache( );
}
private void initCache( ) throws UnexpectedException {
// 1. DDBB access
ArrayList workingModulesCacheable = getWorkingModuleSensors( );
ArrayList alarmsToValidateCacheable = getAlarmsToValidate( );
// 2. Store this information in the CACHE.
// JBoss CACHE functionality
server = MBeanServerLocator.locateJBoss( );
try {
cache = ( PojoCacheMBean ) MBeanProxyExt.create( PojoCacheMBean.class,
"jboss.cache:service=DesaladoraPojoCache",
server );
cache.putObject( "/stpd/adquisition/workingModules", workingModulesCacheable );
cache.putObject( "/stpd/alarms/alarmswatchdog/alarmsToValidate", alarmsToValidateCacheable );
}
catch ( MalformedObjectNameException e ) {
UnexpectedException ue = new UnexpectedException( e.getMessage( ), e );
logger.error("[" + ue.getClass().getName() + "]: " + ue.getMessage(), ue);
}
catch ( CacheException e1 ) {
UnexpectedException ue = new UnexpectedException( e1.getMessage( ), e1 );
logger.error("[" + ue.getClass().getName() + "]: " + ue.getMessage(), ue);
}
}
private void removeCache( ) throws Exception {
server = MBeanServerLocator.locateJBoss( );
try {
cache = ( PojoCacheMBean ) MBeanProxyExt.create( PojoCacheMBean.class,
"jboss.cache:service=DesaladoraPojoCache",
server );
cache.remove( "/" );
}
catch ( MalformedObjectNameException e ) {
UnexpectedException ue = new UnexpectedException( e.getMessage( ), e );
logger.error("[" + ue.getClass().getName() + "]: " + ue.getMessage(), ue);
}
catch ( CacheException e1 ) {
UnexpectedException ue = new UnexpectedException( e1.getMessage( ), e1 );
logger.error("[" + ue.getClass().getName() + "]: " + ue.getMessage(), ue);
}
}
/**
* DDBB access.
* Steps:
* 1. Get IP of all the connected modules (DAH)
* 2. For every module, get all the connected sensors (installed) whose state is ON
*/
private ArrayList getWorkingModuleSensors( ) {
// /// DDBB access //////////////////////////////////////////
// 1. Get IP of all the connected modules (DAH).
ArrayList listOfWorkingModules = new ArrayList( );
ArrayList listOfModules = sensorMs.findAllModules( );
Iterator moduleIter = listOfModules.iterator( );
// 2. From every module, get all the connected sensor (installed) which
// state is ON.
while ( moduleIter.hasNext( ) ) {
DAHModuleDTO module = moduleIter.next( );
ArrayList listOfConnectedSensors = sensorMs.findAllConnectedWorkingSensors( module.getId( ) );
if ( !listOfConnectedSensors.isEmpty( ) )
listOfWorkingModules.add( new WorkingModuleSensors( module.getId( ),
module.getInputNumber( ),
listOfConnectedSensors ) );
}
// /// END OF DDBB ACCESS ///////////////////////////////////
return listOfWorkingModules;
}
/**
* DDBB access.
* Steps:
* 1. Get all alarms to validate (with State of ON).
* 2. From every alarm, get all relevant data.
* @throws UnexpectedException
*/
private ArrayList getAlarmsToValidate( ) throws UnexpectedException {
// /// DDBB access //////////////////////////////////////////
// 1. Get all alarms to validate (with State of ON).
ArrayList listOfAlarmToValidate = new ArrayList( );
ArrayList listOfAlarm = aMs.findAllAlarmsToValidate( );
Iterator iter = listOfAlarm.iterator( );
// 2. From every alarm, get all relevant data
while ( iter.hasNext( ) ) {
AlarmCatalogDTO alarm = iter.next( );
AlarmData alarmToValidate =new AlarmData( alarm.getName( ),
alarm.getActivationRules( ),
AlarmUtils.getActivationRules( alarm.getActivationRules( ) ),
alarm.getAlarmRules( ),
AlarmUtils.getAlarmRules( alarm.getAlarmRules( ) ),
alarm.getSensorComparissonRules( ),
AlarmUtils.getSensorComparissonRules( alarm.getSensorComparissonRules( ) ) );
//Añadimos la info del SMS a enviar
Integer smsId = alarm.getSms( );
if ( smsId != 0 ) {
SmsCatalogFullDataDTO smsFullDto = smsMs.findSmsFullData( smsId );
alarmToValidate.setSmsText( smsFullDto.getContent( ) );
if ( !smsFullDto.getPhonesList( ).isEmpty( ) ) {
List phones = new ArrayList();
for ( PhoneNumberDTO phone : smsFullDto.getPhonesList( ) ) {
//Only phone with the state of ON
if ( phone.getState( ) == State.ON )
phones.add( phone.getPhone( ) );
}
alarmToValidate.setPhoneNumbers( phones );
}
}
logger.debug( alarmToValidate.toString( ) );
listOfAlarmToValidate.add( alarmToValidate );
}
// /// END OF DDBB ACCESS ///////////////////////////////////
return listOfAlarmToValidate;
}
}
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4175394#4175394
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4175394
More information about the jboss-user
mailing list