001: /*
002: License $Id: JoRemoteSessionWrapper.java,v 1.6 2005/03/15 20:09:44 hendriks73 Exp $
003:
004: Copyright (c) 2001-2005 tagtraum industries.
005:
006: LGPL
007: ====
008:
009: jo! is free software; you can redistribute it and/or
010: modify it under the terms of the GNU Lesser General Public
011: License as published by the Free Software Foundation; either
012: version 2.1 of the License, or (at your option) any later version.
013:
014: jo! is distributed in the hope that it will be useful,
015: but WITHOUT ANY WARRANTY; without even the implied warranty of
016: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: Lesser General Public License for more details.
018:
019: You should have received a copy of the GNU Lesser General Public
020: License along with this library; if not, write to the Free Software
021: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022:
023: For LGPL see <http://www.fsf.org/copyleft/lesser.txt>
024:
025:
026: Sun license
027: ===========
028:
029: This release contains software by Sun Microsystems. Therefore
030: the following conditions have to be met, too. They apply to the
031: files
032:
033: - lib/mail.jar
034: - lib/activation.jar
035: - lib/jsse.jar
036: - lib/jcert.jar
037: - lib/jaxp.jar
038: - lib/crimson.jar
039: - lib/servlet.jar
040: - lib/jnet.jar
041: - lib/jaas.jar
042: - lib/jaasmod.jar
043:
044: contained in this release.
045:
046: a. Licensee may not modify the Java Platform
047: Interface (JPI, identified as classes contained within the javax
048: package or any subpackages of the javax package), by creating additional
049: classes within the JPI or otherwise causing the addition to or modification
050: of the classes in the JPI. In the event that Licensee creates any
051: Java-related API and distribute such API to others for applet or
052: application development, you must promptly publish broadly, an accurate
053: specification for such API for free use by all developers of Java-based
054: software.
055:
056: b. Software is confidential copyrighted information of Sun and
057: title to all copies is retained by Sun and/or its licensors. Licensee
058: shall not modify, decompile, disassemble, decrypt, extract, or otherwise
059: reverse engineer Software. Software may not be leased, assigned, or
060: sublicensed, in whole or in part. Software is not designed or intended
061: for use in on-line control of aircraft, air traffic, aircraft navigation
062: or aircraft communications; or in the design, construction, operation or
063: maintenance of any nuclear facility. Licensee warrants that it will not
064: use or redistribute the Software for such purposes.
065:
066: c. Software is provided "AS IS," without a warranty
067: of any kind. ALL EXPRESS OR IMPLIED REPRESENTATIONS AND WARRANTIES,
068: INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
069: PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
070:
071: d. This License is effective until terminated. Licensee may
072: terminate this License at any time by destroying all copies of Software.
073: This License will terminate immediately without notice from Sun if Licensee
074: fails to comply with any provision of this License. Upon such termination,
075: Licensee must destroy all copies of Software.
076:
077: e. Software, including technical data, is subject to U.S.
078: export control laws, including the U.S. Export Administration Act and its
079: associated regulations, and may be subject to export or import regulations
080: in other countries. Licensee agrees to comply strictly with all such
081: regulations and acknowledges that it has the responsibility to obtain
082: licenses to export, re-export, or import Software. Software may not be
083: downloaded, or otherwise exported or re-exported (i) into, or to a national
084: or resident of, Cuba, Iraq, Iran, North Korea, Libya, Sudan, Syria or any
085: country to which the U.S. has embargoed goods; or (ii) to anyone on the
086: U.S. Treasury Department's list of Specially Designated Nations or the U.S.
087: Commerce Department's Table of Denial Orders.
088:
089:
090: Feedback
091: ========
092:
093: We encourage your feedback and suggestions and want to use your feedback to
094: improve the Software. Send all such feedback to:
095: <feedback@tagtraum.com>
096:
097: For more information on tagtraum industries and jo!
098: please see <http://www.tagtraum.com/>.
099:
100:
101: */
102: package com.tagtraum.jobalancer;
103:
104: import com.tagtraum.framework.log.C_Log;
105: import com.tagtraum.framework.log.Log;
106: import com.tagtraum.jo.I_JoHost;
107: import com.tagtraum.jo.I_JoServletContextPeer;
108: import com.tagtraum.jo.I_JoSession;
109: import com.tagtraum.jo.I_JoSessionContext;
110:
111: import javax.servlet.http.HttpSession;
112: import javax.servlet.http.HttpSessionBindingEvent;
113: import javax.servlet.http.HttpSessionBindingListener;
114: import javax.servlet.http.HttpSessionContext;
115: import javax.servlet.ServletContext;
116: import java.rmi.RemoteException;
117: import java.util.Enumeration;
118: import java.util.Vector;
119:
120: /**
121: * Realizes a wrapper to put a {@link I_JoRemoteSession} Object in.
122: *
123: * @author Hendrik Schreiber
124: * @version 1.1beta1 $Id: JoRemoteSessionWrapper.java,v 1.6 2005/03/15 20:09:44 hendriks73 Exp $
125: */
126: public class JoRemoteSessionWrapper implements I_JoSession {
127:
128: /**
129: * Source-Version
130: */
131: public static String vcid = "$Id: JoRemoteSessionWrapper.java,v 1.6 2005/03/15 20:09:44 hendriks73 Exp $";
132:
133: /**
134: * The remote session object
135: */
136: protected I_JoRemoteSession myRemoteSession;
137:
138: /**
139: * The remote session object's id
140: */
141: protected String myID;
142:
143: /**
144: * Cached creation time
145: */
146: protected long myCreationTime;
147:
148: /**
149: * The Host
150: */
151: private I_JoHost myHost;
152:
153: /**
154: * The Peer
155: */
156: private I_JoServletContextPeer myPeer;
157:
158: /**
159: * Initialisiert diese Session.
160: */
161: public JoRemoteSessionWrapper(I_JoRemoteSession aRemoteSession,
162: I_JoServletContextPeer aPeer) {
163: myRemoteSession = aRemoteSession;
164: myPeer = aPeer;
165: myHost = (I_JoHost) aPeer.getHost();
166: myCreationTime = -1;
167: }
168:
169: /**
170: * Returns the {@link I_JoRemoteSession} that is wrapped by
171: * this wrapper.
172: *
173: * @return the wrapped session object
174: */
175: public I_JoRemoteSession getRemoteSession() {
176: return myRemoteSession;
177: }
178:
179: /**
180: * Setzt den Indentifikationsstring dieser Session.
181: *
182: * @exception IllegalStateException falls die SessionID bereits gesetzt worden ist.
183: */
184: public void setId(String anID) {
185: try {
186: myRemoteSession.setId(anID);
187: } catch (RemoteException re) {
188: if (re.detail instanceof RuntimeException) {
189: throw (RuntimeException) re.detail;
190: }
191:
192: if (Log.getLog(myHost.getName()).isLog(C_Log.ERROR)) {
193: Log.getLog(myHost.getName()).log(
194: "Failed to set session ID: " + anID,
195: C_Log.ERROR);
196: Log.getLog(myHost.getName()).log(re, C_Log.ERROR);
197: }
198:
199: throw new JoBalancerIOException(
200: "Failed to set session ID: " + anID, re);
201: }
202: }
203:
204: public ServletContext getServletContext() {
205: return null;
206: }
207:
208: /**
209: * Gibt den Indentifikationsstring dieser Session zurück.
210: *
211: * @exception IllegalStateException falls die Session bereits ungültig ist.
212: * @return SessionID
213: */
214: public String getId() {
215: if (myID != null) {
216: return myID;
217: }
218:
219: try {
220: myID = myRemoteSession.getId();
221:
222: return myID;
223: } catch (RemoteException re) {
224: if (re.detail instanceof RuntimeException) {
225: throw (RuntimeException) re.detail;
226: }
227:
228: if (Log.getLog(myHost.getName()).isLog(C_Log.ERROR)) {
229: Log.getLog(myHost.getName()).log(
230: "Failed to get session ID.", C_Log.ERROR);
231: Log.getLog(myHost.getName()).log(re, C_Log.ERROR);
232: }
233:
234: throw new JoBalancerIOException(
235: "Failed to get session ID.", re);
236: }
237: }
238:
239: /**
240: * Gibt einen leeren HttpSessionContext zurück.
241: *
242: * @return HttpSessionContext
243: * @exception IllegalStateException falls die Session bereits ungültig ist.
244: * @deprecated
245: */
246: public HttpSessionContext getSessionContext() {
247: return new HttpSessionContext() {
248:
249: /**
250: *
251: */
252: public HttpSession getSession(String sessionId) {
253: return null;
254: }
255:
256: /**
257: *
258: */
259: public Enumeration getIds() {
260: return new Vector().elements();
261: }
262:
263: };
264: }
265:
266: /**
267: * Gibt die Zeit zurück, zu der diese Session erzeugt wurde.
268: *
269: * @exception IllegalStateException falls die Session bereits ungültig ist.
270: * @return Zeit in ms seit 1.1.1970 UTC
271: */
272: public long getCreationTime() {
273: if (myCreationTime != -1) {
274: return myCreationTime;
275: }
276:
277: try {
278: myCreationTime = myRemoteSession.getCreationTime();
279:
280: return myCreationTime;
281: } catch (RemoteException re) {
282: if (re.detail instanceof RuntimeException) {
283: throw (RuntimeException) re.detail;
284: }
285:
286: if (Log.getLog(myHost.getName()).isLog(C_Log.ERROR)) {
287: Log.getLog(myHost.getName()).log(
288: "Failed to get session creation time.",
289: C_Log.ERROR);
290: Log.getLog(myHost.getName()).log(re, C_Log.ERROR);
291: }
292:
293: throw new JoBalancerIOException(
294: "Failed to get session creation time.", re);
295: }
296: }
297:
298: /**
299: * Gibt die Zeit zurück, zu der diese Session das letzte mal
300: * benutzt wurde.
301: *
302: * @exception IllegalStateException falls die Session bereits ungültig ist.
303: * @return Zeit in ms seit 1.1.1970 UTC
304: */
305: public long getLastAccessedTime() {
306: try {
307: return myRemoteSession.getLastAccessedTime();
308: } catch (RemoteException re) {
309: if (re.detail instanceof RuntimeException) {
310: throw (RuntimeException) re.detail;
311: }
312:
313: if (Log.getLog(myHost.getName()).isLog(C_Log.ERROR)) {
314: Log.getLog(myHost.getName()).log(
315: "Failed to get last accessed time.",
316: C_Log.ERROR);
317: Log.getLog(myHost.getName()).log(re, C_Log.ERROR);
318: }
319:
320: throw new JoBalancerIOException(
321: "Failed to get last accessed time.", re);
322: }
323: }
324:
325: /**
326: * Markiert den Zeitpunkt der letzten Nutzung.
327: */
328: public void markAccessed() {
329: System.err
330: .println("Call to JoRemoteSessionWrapper.markAccessed(). Why?");
331: }
332:
333: /**
334: * Erklürt diese Session für ungültig.
335: *
336: * @exception IllegalStateException falls die Session bereits ungültig ist.
337: */
338: public void invalidate() {
339: try {
340: myRemoteSession.invalidate();
341: } catch (RemoteException re) {
342: if (re.detail instanceof RuntimeException) {
343: throw (RuntimeException) re.detail;
344: }
345:
346: if (Log.getLog(myHost.getName()).isLog(C_Log.ERROR)) {
347: Log.getLog(myHost.getName()).log(
348: "Failed to invalidate session.", C_Log.ERROR);
349: Log.getLog(myHost.getName()).log(re, C_Log.ERROR);
350: }
351:
352: throw new JoBalancerIOException(
353: "Failed to invalidate session.", re);
354: }
355: }
356:
357: /**
358: * Hinterlegt ein Objekt unter einem Schlüssel in dieser Session.
359: *
360: * @exception IllegalStateException falls die Session bereits ungültig ist.
361: * @param name Schlüssel
362: * @param name Objekt
363: */
364: public void setAttribute(String name, Object value) {
365: try {
366: myRemoteSession.setAttribute(name, value);
367:
368: if (value instanceof HttpSessionBindingListener) {
369: ((HttpSessionBindingListener) value)
370: .valueBound(new HttpSessionBindingEvent(this ,
371: name));
372: }
373: } catch (RemoteException re) {
374: if (re.detail instanceof RuntimeException) {
375: throw (RuntimeException) re.detail;
376: }
377:
378: if (Log.getLog(myHost.getName()).isLog(C_Log.ERROR)) {
379: Log.getLog(myHost.getName()).log(
380: "Failed to set session value/attribute with key: "
381: + name, C_Log.ERROR);
382: Log.getLog(myHost.getName()).log(re, C_Log.ERROR);
383: }
384:
385: throw new JoBalancerIOException(
386: "Failed to set session value/attribute with key: "
387: + name, re);
388: }
389: }
390:
391: /**
392: * Hinterlegt ein Objekt unter einem Schlüssel in dieser Session.
393: *
394: * @exception IllegalStateException falls die Session bereits ungültig ist.
395: * @param name Schlüssel
396: * @param name Objekt
397: */
398: public void putValue(String name, Object value) {
399: setAttribute(name, value);
400: }
401:
402: /**
403: * Gibt ein in dieser Session hinterlegtes Objekt zurück.
404: *
405: * @exception IllegalStateException falls die Session bereits ungültig ist.
406: * @param name Schlüssel
407: * @return Objekt
408: */
409: public Object getAttribute(String name) {
410: try {
411: return myRemoteSession.getAttribute(name);
412: } catch (RemoteException re) {
413: if (re.detail instanceof RuntimeException) {
414: throw (RuntimeException) re.detail;
415: }
416:
417: if (Log.getLog(myHost.getName()).isLog(C_Log.ERROR)) {
418: Log.getLog(myHost.getName()).log(
419: "Failed to get session attribute/value with key: "
420: + name, C_Log.ERROR);
421: Log.getLog(myHost.getName()).log(re, C_Log.ERROR);
422: }
423:
424: throw new JoBalancerIOException(
425: "Failed to get session attribute/value with key: "
426: + name, re);
427: }
428: }
429:
430: /**
431: * Gibt ein in dieser Session hinterlegtes Objekt zurück.
432: *
433: * @exception IllegalStateException falls die Session bereits ungültig ist.
434: * @param name Schlüssel
435: * @return Objekt
436: */
437: public Object getValue(String name) {
438: return getAttribute(name);
439: }
440:
441: /**
442: * Entfernt ein in dieser Session hinterlegtes Objekt zurück.
443: *
444: * @exception IllegalStateException falls die Session bereits ungültig ist.
445: * @param name Schlüssel
446: */
447: public void removeValue(String name) {
448: removeAttribute(name);
449: }
450:
451: /**
452: * Entfernt ein in dieser Session hinterlegtes Objekt zurück.
453: *
454: * @exception IllegalStateException falls die Session bereits ungültig ist.
455: * @param name Schlüssel
456: */
457: public void removeAttribute(String name) {
458: try {
459: myRemoteSession.removeAttribute(name);
460: } catch (RemoteException re) {
461: if (re.detail instanceof RuntimeException) {
462: throw (RuntimeException) re.detail;
463: }
464:
465: if (Log.getLog(myHost.getName()).isLog(C_Log.ERROR)) {
466: Log.getLog(myHost.getName()).log(
467: "Failed to remove session attribute/value with key: "
468: + name, C_Log.ERROR);
469: Log.getLog(myHost.getName()).log(re, C_Log.ERROR);
470: }
471:
472: throw new JoBalancerIOException(
473: "Failed to remove session attribute/value with key: "
474: + name, re);
475: }
476: }
477:
478: /**
479: * Gibt einen Array mit allen Schlüsseln zurück, unter
480: * denen ein Objekt an diese Session gebunden wurde.
481: *
482: * @return Array mit allen Schlüsseln.
483: */
484: public String[] getValueNames() {
485: try {
486: return myRemoteSession.getValueNames();
487: } catch (RemoteException re) {
488: if (re.detail instanceof RuntimeException) {
489: throw (RuntimeException) re.detail;
490: }
491:
492: if (Log.getLog(myHost.getName()).isLog(C_Log.ERROR)) {
493: Log.getLog(myHost.getName()).log(
494: "Failed to get session value names.",
495: C_Log.ERROR);
496: Log.getLog(myHost.getName()).log(re, C_Log.ERROR);
497: }
498:
499: throw new JoBalancerIOException(
500: "Failed to get session value names.", re);
501: }
502: }
503:
504: /**
505: * Gibt einen Array mit allen Schlüsseln zurück, unter
506: * denen ein Objekt an diese Session gebunden wurde.
507: *
508: * @return Array mit allen Schlüsseln.
509: */
510: public Enumeration getAttributeNames() {
511: try {
512: return myRemoteSession.getAttributeNames();
513: } catch (RemoteException re) {
514: if (re.detail instanceof RuntimeException) {
515: throw (RuntimeException) re.detail;
516: }
517:
518: if (Log.getLog(myHost.getName()).isLog(C_Log.ERROR)) {
519: Log.getLog(myHost.getName()).log(
520: "Failed to get session value names.",
521: C_Log.ERROR);
522: Log.getLog(myHost.getName()).log(re, C_Log.ERROR);
523: }
524:
525: throw new JoBalancerIOException(
526: "Failed to get session value names.", re);
527: }
528: }
529:
530: /**
531: * Gibt an, ob eine Session <i>neu</i> ist. Die genaue Definition
532: * von <i>neu</i> ist der Servlet-API-Spezifikation zu entnehmen.
533: *
534: * @return <code>true</code> oder <code>false</code>
535: */
536: public boolean isNew() {
537: try {
538: return myRemoteSession.isNew();
539: } catch (RemoteException re) {
540: if (re.detail instanceof RuntimeException) {
541: throw (RuntimeException) re.detail;
542: }
543:
544: if (Log.getLog(myHost.getName()).isLog(C_Log.ERROR)) {
545: Log.getLog(myHost.getName()).log(
546: "Failed to call isNew().", C_Log.ERROR);
547: Log.getLog(myHost.getName()).log(re, C_Log.ERROR);
548: }
549:
550: throw new JoBalancerIOException("Failed to call isNew().",
551: re);
552: }
553: }
554:
555: /**
556: * Gibt die maximale Zeit, die eine Session inaktiv existieren kann,
557: * in Sekunden zurück.
558: *
559: * @return Zeit in Sekunden.
560: */
561: public int getMaxInactiveInterval() {
562: try {
563: return myRemoteSession.getMaxInactiveInterval();
564: } catch (RemoteException re) {
565: if (re.detail instanceof RuntimeException) {
566: throw (RuntimeException) re.detail;
567: }
568:
569: if (Log.getLog(myHost.getName()).isLog(C_Log.ERROR)) {
570: Log.getLog(myHost.getName()).log(
571: "Failed to call getMaxInactiveInterval().",
572: C_Log.ERROR);
573: Log.getLog(myHost.getName()).log(re, C_Log.ERROR);
574: }
575:
576: throw new JoBalancerIOException(
577: "Failed to call getMaxInactiveInterval().", re);
578: }
579: }
580:
581: /**
582: * Setzt die maximale Zeit, die eine Session inaktiv existieren kann.
583: *
584: * @param interval Zeit in Sekunden.
585: */
586: public void setMaxInactiveInterval(int interval) {
587: try {
588: myRemoteSession.setMaxInactiveInterval(interval);
589: } catch (RemoteException re) {
590: if (re.detail instanceof RuntimeException) {
591: throw (RuntimeException) re.detail;
592: }
593:
594: if (Log.getLog(myHost.getName()).isLog(C_Log.ERROR)) {
595: Log.getLog(myHost.getName()).log(
596: "Failed to call setMaxInactiveInterval("
597: + interval + ").", C_Log.ERROR);
598: Log.getLog(myHost.getName()).log(re, C_Log.ERROR);
599: }
600:
601: throw new JoBalancerIOException(
602: "Failed to call setMaxInactiveInterval(" + interval
603: + ").", re);
604: }
605: }
606:
607: /**
608: * Indicates whether this session is still valid.
609: */
610: public boolean isValid() {
611: try {
612: return myRemoteSession.isValid();
613: } catch (RemoteException re) {
614: if (re.detail instanceof RuntimeException) {
615: throw (RuntimeException) re.detail;
616: }
617:
618: if (Log.getLog(myHost.getName()).isLog(C_Log.ERROR)) {
619: Log.getLog(myHost.getName()).log(
620: "Failed to call isValid().", C_Log.ERROR);
621: Log.getLog(myHost.getName()).log(re, C_Log.ERROR);
622: }
623:
624: throw new JoBalancerIOException(
625: "Failed to call isValid().", re);
626: }
627: }
628:
629: /**
630: * Ruft die Methode {@link I_JoSessionContext#sync(I_JoSession)}
631: * auf.
632: * Diese ist in der Defaultrealisierung leer.
633: */
634: public void sync() {
635: System.err.println("Call to JoRemoteSession.sync(). Why?");
636: }
637:
638: /**
639: * Setzt den SessionContext dieser Session.
640: *
641: * @param aContext zugehöriger SessionContext
642: * @exception IllegalStateException falls der SessionContext bereits gesetzt worden ist.
643: */
644: public void setSessionContext(I_JoSessionContext aContext) {
645: // not necessary for JoRemoteSessionWrapper. Is done in the real session (rik)
646: }
647:
648: /*
649: *
650: * private synchronized void writeObject(java.io.ObjectOutputStream s) throws IOException
651: * {
652: * String logname = sessionContext.getServletContextPeer().getHost().getName();
653: * try {
654: * s.defaultWriteObject();
655: * }
656: * catch (NotSerializableException nse) {
657: * Log.getLog(logname).log("Failed to serialize session " + id + ": " + nse.toString());
658: * }
659: * if (Log.isLog(logname)) {
660: * Enumeration e = values.getWarnings();
661: * while (e.hasMoreElements()) {
662: * Log.getLog(logname).log("Session " + id + ": " + (String)e.nextElement());
663: * }
664: * }
665: * }
666: *
667: * private synchronized void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException, NotActiveException
668: * {
669: * s.defaultReadObject();
670: * }
671: *
672: */
673: }
|