Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WFLY-850 Adding transaction timeout info to programmatic timer #6088

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public SessionBeanComponentCreateService(final ComponentConfiguration componentC
processTxAttr(sessionBeanComponentDescription, MethodIntf.TIMER, method);
}
}
if (sessionBeanComponentDescription.getTimeoutMethod() != null) {
this.processTxAttr(sessionBeanComponentDescription, MethodIntf.TIMER,
sessionBeanComponentDescription.getTimeoutMethod());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a chance that the same method might have processTxAttr() called on it twice, and if so, is there protection in that method to avoid any kind of duplication nonsense?

Patch otherwise looks reasonable to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method processTxAttr() adds information about attributes and timeouts to maps. Keys in those maps are objects of class MethodTransactionAttributeKey. This class contains information about both method and context of invocation. So there is no protection against method being called many times, but running it many times will leave those maps in the same state. On the other hand, I see one more problem here. Before my fix transaction timeouts were added to public @timeout methods with context other than timer and it didn't prevented information about timeout to be propagated to those methods when they were executed from timer context.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this patch OK to merge as is, or do you want to try and verify/fix this second issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this patch can be merged because the second issue is independent. I can leave the Jira open and investigate it further. If it required fix then I would prepare another patch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK in that case this has my +1

}

final EJBViewDescription local = sessionBeanComponentDescription.getEjbLocalView();
ejbLocalObjectView = local == null ? null : local.getServiceName();
final EJBViewDescription remote = sessionBeanComponentDescription.getEjbRemoteView();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.tx.timeout;

import javax.annotation.Resource;
import javax.transaction.TransactionManager;

import com.arjuna.ats.jta.transaction.Transaction;

/**
* @author Tomasz Adamski
*/
public abstract class AbstractTxBean {

@Resource(lookup = "java:jboss/TransactionManager")
private TransactionManager transactionManager;

private Transaction transaction;

protected int checkTimeoutValue() {
try {
transaction = (Transaction) transactionManager.getTransaction();
return transaction.getTimeout();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.tx.timeout;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import javax.ejb.Schedule;
import javax.ejb.Stateless;
import javax.ejb.Timer;

import org.jboss.ejb3.annotation.TransactionTimeout;

/**
* @author Tomasz Adamski
*/
@Stateless
public class PrivateTxScheduleBean extends AbstractTxBean {
private static final CountDownLatch latch = new CountDownLatch(1);
private static final int TIMER_CALL_WAITING_S = 30;

private static volatile boolean timerServiceCalled = false;
private static volatile int timeout = 0;

@Schedule(second = "*", minute = "*", hour = "*", persistent = false, info = "info", timezone = "Europe/Prague")
@TransactionTimeout(value = 5)
private void timeout(Timer timer) {
timeout = checkTimeoutValue();
timerServiceCalled = true;
latch.countDown();
}

public static boolean awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}

public static int getTimeout() {
return timeout;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.tx.timeout;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;
import javax.ejb.Remote;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;

import org.jboss.ejb3.annotation.TransactionTimeout;

/**
* @author Tomasz Adamski
*/

@Stateless
@Remote(TimeoutBeanRemoteView.class)
public class PrivateTxTimeoutBean extends AbstractTxBean implements TimeoutBeanRemoteView {

private static final int TIMER_CALL_WAITING_S = 30;
private static final int DURATION = 100;

private static volatile CountDownLatch latch = new CountDownLatch(1);

private static volatile boolean timerServiceCalled = false;
private static volatile int timeout = 0;

@Resource
private SessionContext sessionContext;

@Resource
private TimerService timerService;

@Override
public void startTimer() {
timerService.createSingleActionTimer(DURATION, new TimerConfig());
}

@Timeout
@TransactionTimeout(value = 5)
private void timeout(final Timer timer) {
timeout = checkTimeoutValue();
timerServiceCalled = true;
latch.countDown();
}

public static boolean awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}

public static int getTimeout(){
return timeout;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.tx.timeout;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import javax.ejb.Schedule;
import javax.ejb.Stateless;
import javax.ejb.Timer;

import org.jboss.ejb3.annotation.TransactionTimeout;

/**
* @author Tomasz Adamski
*/
@Stateless
public class PublicTxScheduleBean extends AbstractTxBean {
private static final CountDownLatch latch = new CountDownLatch(1);
private static final int TIMER_CALL_WAITING_S = 30;

private static volatile boolean timerServiceCalled = false;
private static volatile int timeout = 0;

@Schedule(second = "*", minute = "*", hour = "*", persistent = false, info = "info", timezone = "Europe/Prague")
@TransactionTimeout(value = 5)
public void timeout(Timer timer) {
timeout = checkTimeoutValue();
timerServiceCalled = true;
latch.countDown();
}

public static boolean awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}

public static int getTimeout() {
return timeout;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.tx.timeout;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;
import javax.ejb.Remote;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;

import org.jboss.ejb3.annotation.TransactionTimeout;

/**
* @author Tomasz Adamski
*/

@Stateless
@Remote(TimeoutBeanRemoteView.class)
public class PublicTxTimoutBean extends AbstractTxBean implements TimeoutBeanRemoteView {

private static final int TIMER_CALL_WAITING_S = 30;
private static final int DURATION = 100;

private static volatile CountDownLatch latch = new CountDownLatch(1);

private static volatile boolean timerServiceCalled = false;
private static volatile int timeout = 0;

@Resource
private SessionContext sessionContext;

@Resource
private TimerService timerService;

@Override
public void startTimer() {
timerService.createSingleActionTimer(DURATION, new TimerConfig());
}

@Timeout
@TransactionTimeout(value = 5)
public void timeout(final Timer timer) {
timeout = checkTimeoutValue();
timerServiceCalled = true;
latch.countDown();
}

public static boolean awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}

public static int getTimeout(){
return timeout;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.tx.timeout;

public interface TimeoutBeanRemoteView {
void startTimer();
}