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:
023: package org.jboss.ejb3.test.stateful.nested.base;
024:
025: import java.rmi.dgc.VMID;
026:
027: import javax.ejb.Remote;
028: import javax.ejb.Remove;
029: import javax.ejb.Stateful;
030:
031: import org.jboss.logging.Logger;
032:
033: /**
034: * A BeanMonitorBean.
035: *
036: * @author <a href="brian.stansberry@jboss.com">Brian Stansberry</a>
037: * @version $Revision: 1.1 $
038: */
039: public class BeanMonitorBean implements BeanMonitor {
040: protected Logger log = Logger.getLogger(getClass());
041:
042: protected TopLevel parent;
043: protected MidLevel nested;
044: protected MidLevel localNested;
045: protected DeepNestedStateful deepNested;
046: protected DeepNestedStateful localDeepNested;
047:
048: public VMID getVMID() {
049: return VMTracker.VMID;
050: }
051:
052: public void monitor(TopLevel topLevel) {
053: this .parent = topLevel;
054: log.debug("parent is " + parent);
055: this .nested = parent.getNested();
056: log.debug("nested is " + nested);
057: this .localNested = parent.getLocalNested();
058: log.debug("localNested is " + localNested);
059: this .deepNested = nested.getDeepNestedStateful();
060: log.debug("deepNested is " + deepNested);
061: this .localDeepNested = localNested.getDeepNestedStateful();
062: log.debug("localDeepNested is " + localDeepNested);
063: }
064:
065: public String getDeepNestedId() {
066: try {
067: return deepNested.getInternalId();
068: } catch (Exception e) {
069: log.debug("getDeepNestedId() " + e.getLocalizedMessage());
070: return "ERROR";
071: }
072: }
073:
074: public String getLocalDeepNestedId() {
075: try {
076: return localDeepNested.getInternalId();
077: } catch (Exception e) {
078: log.debug("getLocalDeepNestedId() "
079: + e.getLocalizedMessage());
080: return "ERROR";
081: }
082: }
083:
084: public int getParentPassivations() {
085: try {
086: return parent.getPrePassivate();
087: } catch (Exception e) {
088: log.debug("getParentPassivations() "
089: + e.getLocalizedMessage());
090: return -1;
091: }
092: }
093:
094: public int getNestedPassivations() {
095: try {
096: return nested.getPrePassivate();
097: } catch (Exception e) {
098: log.debug("getNestedPassivations() "
099: + e.getLocalizedMessage());
100: return -1;
101: }
102: }
103:
104: public int getLocalNestedPassivations() {
105: try {
106: return localNested.getPrePassivate();
107: } catch (Exception e) {
108: log.debug("getLocalNestedPassivations() "
109: + e.getLocalizedMessage());
110: return -1;
111: }
112: }
113:
114: public int getDeepNestedPassivations() {
115: try {
116: return deepNested.getPrePassivate();
117: } catch (Exception e) {
118: log.debug("getDeepNestedPassivations() "
119: + e.getLocalizedMessage());
120: return -1;
121: }
122: }
123:
124: public int getLocalDeepNestedPassivations() {
125: try {
126: return localDeepNested.getPrePassivate();
127: } catch (Exception e) {
128: log.debug("getLocalDeepNestedPassivations() "
129: + e.getLocalizedMessage());
130: return -1;
131: }
132: }
133:
134: public int getParentActivations() {
135: try {
136: return parent.getPostActivate();
137: } catch (Exception e) {
138: log.debug("getParentActivations() "
139: + e.getLocalizedMessage());
140: return -1;
141: }
142: }
143:
144: public int getNestedActivations() {
145: try {
146: return nested.getPostActivate();
147: } catch (Exception e) {
148: log.debug("getNestedActivations() "
149: + e.getLocalizedMessage());
150: return -1;
151: }
152: }
153:
154: public int getLocalNestedActivations() {
155: try {
156: return localNested.getPostActivate();
157: } catch (Exception e) {
158: log.debug("getLocalNestedActivations() "
159: + e.getLocalizedMessage());
160: return -1;
161: }
162: }
163:
164: public int getDeepNestedActivations() {
165: try {
166: return deepNested.getPostActivate();
167: } catch (Exception e) {
168: log.debug("getDeepNestedActivations() "
169: + e.getLocalizedMessage());
170: return -1;
171: }
172: }
173:
174: public int getLocalDeepNestedActivations() {
175: try {
176: return localDeepNested.getPostActivate();
177: } catch (Exception e) {
178: log.debug("getLocalDeepNestedActivations() "
179: + e.getLocalizedMessage());
180: return -1;
181: }
182: }
183:
184: public boolean removeParent() {
185: try {
186: parent.remove();
187: return true;
188: } catch (Exception e) {
189: log.debug("removeParent() " + e.getLocalizedMessage());
190: return false;
191: }
192: }
193:
194: public boolean removeNested() {
195: try {
196: nested.remove();
197: return true;
198: } catch (Exception e) {
199: log.debug("removeNested() " + e.getLocalizedMessage());
200: return false;
201: }
202: }
203:
204: public boolean removeLocalNested() {
205: try {
206: localNested.remove();
207: return true;
208: } catch (Exception e) {
209: log.debug("removeLocalNested() " + e.getLocalizedMessage());
210: return false;
211: }
212: }
213:
214: public boolean removeDeepNested() {
215: try {
216: deepNested.remove();
217: return true;
218: } catch (Exception e) {
219: log.debug("removeDeepNested() " + e.getLocalizedMessage());
220: return false;
221: }
222: }
223:
224: public boolean removeLocalDeepNested() {
225: try {
226: localDeepNested.remove();
227: return true;
228: } catch (Exception e) {
229: log.debug("removeLocalDeepNested() "
230: + e.getLocalizedMessage());
231: return false;
232: }
233: }
234:
235: @Remove
236: public void remove() {
237: log.debug("Being removed");
238: removeParent();
239: removeNested();
240: removeLocalNested();
241: removeDeepNested();
242: removeLocalDeepNested();
243: }
244:
245: }
|