KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nl > justobjects > pushlet > core > SerializedAdapter


1 // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
2
// Distributable under LGPL license. See terms of license at gnu.org.
3

4 package nl.justobjects.pushlet.core;
5
6 import javax.servlet.http.HttpServletResponse JavaDoc;
7 import java.io.IOException JavaDoc;
8 import java.io.ObjectOutputStream JavaDoc;
9
10 /**
11  * Implementation of ClientAdapter that sends Events as serialized objects.
12  *
13  * NOTE: You are discouraged to use this adapter, since it is Java-only
14  * and may have JVM-specific problems. Far better choice is to use XML
15  * and the XMLAdapter.
16  *
17  * @version $Id: SerializedAdapter.java,v 1.3 2005/02/28 12:45:59 justb Exp $
18  * @author Just van den Broecke - Just Objects &copy;
19  */

20 class SerializedAdapter implements ClientAdapter {
21     private ObjectOutputStream JavaDoc out = null;
22     public static final String JavaDoc CONTENT_TYPE = "application/x-java-serialized-object";
23     private HttpServletResponse JavaDoc servletRsp;
24
25     /** Initialize. */
26     public SerializedAdapter(HttpServletResponse JavaDoc aServletResponse) {
27         servletRsp = aServletResponse;
28     }
29
30     public void start() throws IOException JavaDoc {
31
32         servletRsp.setContentType(CONTENT_TYPE);
33
34         // Use a serialized object output stream
35
out = new ObjectOutputStream JavaDoc(servletRsp.getOutputStream());
36
37         // Don't need this further
38
servletRsp = null;
39     }
40
41     /** Push Event to client. */
42     public void push(Event anEvent) throws IOException JavaDoc {
43         out.writeObject(anEvent);
44
45         out.flush();
46     }
47
48
49     public void stop() throws IOException JavaDoc {
50     }
51 }
52
53 /*
54  * $Log: SerializedAdapter.java,v $
55  * Revision 1.3 2005/02/28 12:45:59 justb
56  * introduced Command class
57  *
58  * Revision 1.2 2005/02/21 11:50:46 justb
59  * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
60  *
61  * Revision 1.1 2005/02/18 10:07:23 justb
62  * many renamings of classes (make names compact)
63  *
64  * Revision 1.4 2004/09/03 22:35:37 justb
65  * Almost complete rewrite, just checking in now
66  *
67  * Revision 1.3 2003/08/15 08:37:40 justb
68  * fix/add Copyright+LGPL file headers and footers
69  *
70  * Revision 1.2 2003/05/18 16:13:48 justb
71  * fixed blocking for java.net.URL with HTTP/1.1 (JVMs > 1.1)
72  *
73  * Revision 1.1.1.1 2002/09/24 21:02:31 justb
74  * import to sourceforge
75  *
76  * Revision 1.1.1.1 2002/09/20 22:48:18 justb
77  * import to SF
78  *
79  * Revision 1.1.1.1 2002/09/20 14:19:03 justb
80  * first import into SF
81  *
82  * Revision 1.5 2002/04/15 20:42:41 just
83  * reformatting and renaming GuardedQueue to EventQueue
84  *
85  * Revision 1.4 2000/12/27 22:39:35 just
86  * no message
87  *
88  * Revision 1.3 2000/08/21 20:48:29 just
89  * added CVS log and id tags plus copyrights
90  *
91  *
92  */

93
Popular Tags