001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb3.test.cache;
023:
024: import javax.ejb.Local;
025: import javax.ejb.PostActivate;
026: import javax.ejb.PrePassivate;
027: import javax.ejb.Remote;
028: import javax.ejb.Stateful;
029: import javax.ejb.Remove;
030: import javax.naming.InitialContext;
031: import org.jboss.annotation.ejb.cache.Cache;
032: import org.jboss.annotation.ejb.cache.tree.CacheConfig;
033:
034: /**
035: * Comment
036: *
037: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
038: * @version $Revision: 57207 $
039: */
040: @Stateful
041: @Cache(org.jboss.ejb3.cache.tree.StatefulTreeCache.class)
042: @CacheConfig(name="jboss.cache:service=EJB3SFSBClusteredCache",maxSize=1000,idleTimeoutSeconds=1)
043: @Local(StatefulLocal.class)
044: @Remote(StatefulRemote.class)
045: public class StatefulBean implements StatefulRemote,
046: java.io.Serializable, StatefulLocal {
047: public static boolean postActivateCalled = false;
048: public static boolean prePassivateCalled = false;
049:
050: private String state;
051:
052: public long bench(int iterations) throws Exception {
053: InitialContext ctx = new InitialContext();
054: StatefulLocal local = (StatefulLocal) ctx
055: .lookup("StatefulBean/local");
056: long start = System.currentTimeMillis();
057: for (int i = 0; i < iterations; i++) {
058: local.getState();
059: }
060: long end = System.currentTimeMillis() - start;
061: System.out.println(iterations + " stateful iterations took: "
062: + end);
063: return end;
064: }
065:
066: public void longRunning() throws Exception {
067: Thread.sleep(11000);
068: }
069:
070: @Remove
071: public void done() {
072: }
073:
074: public boolean getPostActivate() {
075: return postActivateCalled;
076: }
077:
078: public boolean getPrePassivate() {
079: return prePassivateCalled;
080: }
081:
082: public void setState(String state) {
083: this .state = state;
084: }
085:
086: public String getState() {
087: return this .state;
088: }
089:
090: public void reset() {
091: state = null;
092: postActivateCalled = false;
093: prePassivateCalled = false;
094: }
095:
096: @PostActivate
097: public void postActivate() {
098: postActivateCalled = true;
099: }
100:
101: @PrePassivate
102: public void prePassivate() {
103: prePassivateCalled = true;
104: }
105:
106: }
|