Source Code Cross Referenced for StatefulBeanRefImpl.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » ha » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.ha 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * High Availability Service (HA) for JOnAS
003:         *
004:         * Copyright (C) 2006 Distributed Systems Lab.
005:         * Universidad Polit??cnica de Madrid (Spain)
006:         * Contact: http://lsd.ls.fi.upm.es/lsd
007:         *
008:         * This library is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU Lesser General Public
010:         * License as published by the Free Software Foundation; either
011:         * version 2.1 of the License, or any later version.
012:         *
013:         * This library is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016:         * Lesser General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU Lesser General Public
019:         * License along with this library; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
021:         * USA
022:         *
023:         * --------------------------------------------------------------------------
024:         * $Id: StatefulBeanRefImpl.java 9684 2006-10-06 12:23:28Z benoitf $
025:         * --------------------------------------------------------------------------
026:         */package org.objectweb.jonas.ha;
027:
028:        import java.io.ByteArrayInputStream;
029:        import java.io.ByteArrayOutputStream;
030:        import java.lang.reflect.Field;
031:        import java.lang.reflect.Method;
032:        import java.lang.reflect.Modifier;
033:
034:        import javax.ejb.SessionBean;
035:
036:        import org.objectweb.carol.cmi.configuration.TraceCmi;
037:        import org.objectweb.carol.cmi.ha.StatefulBeanReference;
038:        import org.objectweb.jonas_ejb.container.JRepStatefulInputStream;
039:        import org.objectweb.jonas_ejb.container.JRepStatefulOutputStream;
040:        import org.objectweb.jonas_ejb.container.JStatefulContext;
041:        import org.objectweb.jonas_ejb.container.JStatefulSwitch;
042:        import org.objectweb.jonas_ejb.deployment.api.SessionStatefulDesc;
043:
044:        /**
045:         * This class implements reference to beans
046:         * @author Francisco Perez-Sorrosal (fpsorrosal@no-spam@fi.upm.es)
047:         * @author Alberto Paz-Jimenez (apaz@no-spam@fi.upm.es)
048:         */
049:        public class StatefulBeanRefImpl implements  StatefulBeanReference {
050:
051:            private JStatefulSwitch bs;
052:
053:            public StatefulBeanRefImpl(JStatefulSwitch bs) {
054:                this .bs = bs;
055:            }
056:
057:            public byte[] getState() {
058:                return getStatefulState(bs);
059:            }
060:
061:            public boolean isModified() {
062:                SessionStatefulDesc ssd = (SessionStatefulDesc) bs
063:                        .getBeanFactory().getDeploymentDescriptor();
064:                if (ssd.hasIsModifiedMethod()) {
065:                    Method isModifiedMethod = ssd.getIsModifiedMethod();
066:                    try {
067:                        SessionBean sb = ((JStatefulSwitch) bs)
068:                                .getStatefulContext().getInstance();
069:                        return ((Boolean) isModifiedMethod.invoke(sb,
070:                                (Object[]) null)).booleanValue();
071:                    } catch (Exception e) {
072:                        e.printStackTrace();
073:                        return true;
074:                    }
075:                } else {
076:                    return true;
077:                }
078:            }
079:
080:            /* (non-Javadoc)
081:             * @see org.objectweb.carol.cmi.ha.BeanReference#injectState(byte[])
082:             */
083:            public void injectState(byte[] state) {
084:                if (bs != null) {
085:                    injectState(bs, state);
086:                }
087:            }
088:
089:            /**
090:             * Extracts the state of the stateful session bean
091:             * @param jss the related switch of the stateful session bean to access the
092:             *        SFBS's real instance
093:             */
094:            static private byte[] getStatefulState(JStatefulSwitch jss) {
095:                ByteArrayOutputStream bos = new ByteArrayOutputStream();
096:                JStatefulContext ctx = jss.getStatefulContext();
097:                try {
098:                    SessionBean instance = ctx.getInstance();
099:                    JRepStatefulOutputStream out = new JRepStatefulOutputStream(
100:                            bos);
101:                    out.writeObject(instance);
102:                    out.close();
103:                } catch (Exception e) {
104:                    TraceCmi.error("Can't get state of "
105:                            + jss.getBeanFactory().getEJBName() + "inst.");
106:                }
107:                return bos.toByteArray();
108:            }
109:
110:            /**
111:             * Injects the serialized state of the bean in the corresponding beanSwitch
112:             * @param bean target bean
113:             * @param beanState state to inject
114:             */
115:            static private void injectState(JStatefulSwitch bean,
116:                    byte[] beanState) {
117:
118:                JStatefulContext bctx = (JStatefulContext) bean
119:                        .getStatefulContext();
120:                try {
121:                    ByteArrayInputStream bais = new ByteArrayInputStream(
122:                            beanState);
123:                    JRepStatefulInputStream in = new JRepStatefulInputStream(
124:                            bais, bean);
125:                    Object obj = in.readObject();
126:                    //if (TraceCmi.isDebugCmiHA())
127:                    //  TraceCmi.debugCmiHA("\tDeserialized object:" + obj);
128:                    in.close();
129:                    SessionBean sb = (SessionBean) obj;
130:
131:                    // Deal with transient values
132:                    SessionBean oldInstance = bctx.getInstance();
133:                    Field[] fields = sb.getClass().getDeclaredFields();
134:                    for (int i = 0; i < fields.length; i++) {
135:                        if (Modifier.isTransient(fields[i].getModifiers())) {
136:                            try {
137:                                fields[i].setAccessible(true);
138:                                fields[i].set(sb, fields[i].get(oldInstance));
139:                            } catch (IllegalAccessException iae) {
140:                                iae.printStackTrace();
141:                            } catch (SecurityException se) {
142:                                se.printStackTrace();
143:                            }
144:                        }
145:                    }
146:
147:                    bctx.setInstance(sb);
148:                    sb.ejbActivate();
149:                } catch (Exception e) {
150:                    e.printStackTrace();
151:                }
152:            }
153:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.