-Scheduler (JEE7) en Cluster en Wildfly 9:
NOTA: Esto aunque se puede hacer en Wildfly8 no funciona, ya que se ejecuta en todos los nodos. Los de JBoss no han implementado que se ejecute sólo en 1 hasta el Wildfly9.
Si se quiere poner un @Scheduler en un cluster y que sólo sea ejecutado en uno de los nodos del cluster.
Hay que hacer varias cosas:
1.- Marcar el @Scheduler como persistente:
@Schedule(hour = "*", minute = "*/5", second = "0",
persistent = true
)
2.- Configurar los nodos para que los datos del scheduler esten en una BD compartida (standalone-ha.xml).
Hay que cambiar el «file-store» por esto:
<timer-service thread-pool-name="default" default-data-store="clustered-store">
<data-stores>
<database-data-store name="clustered-store" datasource-jndi-name="java:jboss/datasources/MySQLDS" database="mysql" partition="timer"/>
</data-stores>
</timer-service>
3.- Para que funcione el database-store con Mysql hay que modificar el siguiente fichero creando sentencias adecuadas para MySQL:
vi $WILDFLY_HOME/modules/system/layers/base/org/jboss/as/ejb3/main/timers/timer-sql.properties
Crear las sentencias para mysql:
create-table.mysql=CREATE TABLE JBOSS_EJB_TIMER (ID VARCHAR PRIMARY KEY NOT NULL, TIMED_OBJECT_ID VARCHAR NOT NULL, INITIAL_DATE TIMESTAMP, REPEAT_INTERVAL LONG, NEXT_DATE TIMESTAMP, PREVIOUS_RUN TIMESTAMP, PRIMARY_KEY VARCHAR, INFO VARCHAR, TIMER_STATE VARCHAR, SCHEDULE_EXPR_SECOND VARCHAR, SCHEDULE_EXPR_MINUTE VARCHAR, SCHEDULE_EXPR_HOUR VARCHAR,SCHEDULE_EXPR_DAY_OF_WEEK VARCHAR, SCHEDULE_EXPR_DAY_OF_MONTH VARCHAR, SCHEDULE_EXPR_MONTH VARCHAR, SCHEDULE_EXPR_YEAR VARCHAR, SCHEDULE_EXPR_START_DATE VARCHAR, SCHEDULE_EXPR_END_DATE VARCHAR, SCHEDULE_EXPR_TIMEZONE VARCHAR, AUTO_TIMER BOOLEAN, TIMEOUT_METHOD_NAME VARCHAR, TIMEOUT_METHOD_DECLARING_CLASS VARCHAR, TIMEOUT_METHOD_DESCRIPTOR VARCHAR, CALENDAR_TIMER BOOLEAN, PARTITION VARCHAR NOT NULL);
create-timer.mysql=INSERT INTO JBOSS_EJB_TIMER (ID, TIMED_OBJECT_ID, INITIAL_DATE, REPEAT_INTERVAL, NEXT_DATE, PREVIOUS_RUN, PRIMARY_KEY, INFO, TIMER_STATE, SCHEDULE_EXPR_SECOND, SCHEDULE_EXPR_MINUTE, SCHEDULE_EXPR_HOUR, SCHEDULE_EXPR_DAY_OF_WEEK, SCHEDULE_EXPR_DAY_OF_MONTH, SCHEDULE_EXPR_MONTH, SCHEDULE_EXPR_YEAR, SCHEDULE_EXPR_START_DATE, SCHEDULE_EXPR_END_DATE, SCHEDULE_EXPR_TIMEZONE, AUTO_TIMER, TIMEOUT_METHOD_NAME, TIMEOUT_METHOD_DECLARING_CLASS, TIMEOUT_METHOD_DESCRIPTOR, CALENDAR_TIMER, PARTITION) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
update-timer.mysql=UPDATE JBOSS_EJB_TIMER SET NEXT_DATE=?, PREVIOUS_RUN=?, TIMER_STATE=? WHERE TIMED_OBJECT_ID=? and ID=? AND PARTITION=?;
delete-timer.mysql=DELETE FROM JBOSS_EJB_TIMER WHERE TIMED_OBJECT_ID=? and ID=? AND PARTITION=?;
load-all-timers=SELECT ID, TIMED_OBJECT_ID, INITIAL_DATE, REPEAT_INTERVAL, NEXT_DATE, PREVIOUS_RUN, PRIMARY_KEY, INFO, TIMER_STATE, SCHEDULE_EXPR_SECOND, SCHEDULE_EXPR_MINUTE, SCHEDULE_EXPR_HOUR, SCHEDULE_EXPR_DAY_OF_WEEK, SCHEDULE_EXPR_DAY_OF_MONTH, SCHEDULE_EXPR_MONTH, SCHEDULE_EXPR_YEAR, SCHEDULE_EXPR_START_DATE, SCHEDULE_EXPR_END_DATE, SCHEDULE_EXPR_TIMEZONE, AUTO_TIMER, TIMEOUT_METHOD_NAME, TIMEOUT_METHOD_DECLARING_CLASS, TIMEOUT_METHOD_DESCRIPTOR, CALENDAR_TIMER FROM JBOSS_EJB_TIMER WHERE TIMED_OBJECT_ID=? AND PARTITION=?;
load-timer.mysql=SELECT ID, TIMED_OBJECT_ID, INITIAL_DATE, REPEAT_INTERVAL, NEXT_DATE, PREVIOUS_RUN, PRIMARY_KEY, INFO, TIMER_STATE, SCHEDULE_EXPR_SECOND, SCHEDULE_EXPR_MINUTE, SCHEDULE_EXPR_HOUR, SCHEDULE_EXPR_DAY_OF_WEEK, SCHEDULE_EXPR_DAY_OF_MONTH, SCHEDULE_EXPR_MONTH, SCHEDULE_EXPR_YEAR, SCHEDULE_EXPR_START_DATE, SCHEDULE_EXPR_END_DATE, SCHEDULE_EXPR_TIMEZONE, AUTO_TIMER, TIMEOUT_METHOD_NAME, TIMEOUT_METHOD_DECLARING_CLASS, TIMEOUT_METHOD_DESCRIPTOR, CALENDAR_TIMER FROM JBOSS_EJB_TIMER WHERE TIMED_OBJECT_ID=? and ID=? AND PARTITION=?;
Y con esto ya se ejecutara sólo en 1 nodo del cluster.
0 comentarios