View Javadoc

1   /**********************************************************************
2    * EJConstants
3    * created on 27.02.2005 by netseeker
4    * $Source: /cvsroot/ejoe/EJOE/src/de/netseeker/ejoe/EJConstants.java,v $
5    * $Date: 2007/11/17 10:59:40 $
6    * $Revision: 1.47 $
7    *
8    * ====================================================================
9    *
10   *  Copyright 2005-2006 netseeker aka Michael Manske
11   *
12   *  Licensed under the Apache License, Version 2.0 (the "License");
13   *  you may not use this file except in compliance with the License.
14   *  You may obtain a copy of the License at
15   *
16   *      http://www.apache.org/licenses/LICENSE-2.0
17   *
18   *  Unless required by applicable law or agreed to in writing, software
19   *  distributed under the License is distributed on an "AS IS" BASIS,
20   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21   *  See the License for the specific language governing permissions and
22   *  limitations under the License.
23   * ====================================================================
24   *
25   * This file is part of the ejoe framework.
26   * For more information on the author, please see
27   * <http://www.manskes.de/>.
28   *
29   *********************************************************************/
30  package de.netseeker.ejoe;
31  
32  import de.netseeker.ejoe.adapter.ObjectStreamAdapter;
33  import de.netseeker.ejoe.adapter.XStreamAdapter;
34  
35  /***
36   * @author netseeker
37   */
38  public final class EJConstants
39  {
40      public static final String EJOE_VERSION                 = "0.4.1";
41  
42      /***
43       * magic integer used to determine if the default ejoe protocol or HTTP is used
44       */
45      public static final int    EJOE_MAGIC_NUMBER            = 0xE10EBABE;
46  
47      /***
48       * EJOEs custom EOF int value
49       */
50      public static final int    EJOE_EOF                     = -2;
51  
52      /***
53       * default (de)serialize adapter implementation used if no adapter was requested
54       */
55      public static Class        EJOE_DEFAULT_ADAPTER;
56  
57      /***
58       * Default charset used for de/encoding operations
59       */
60      public static final String EJOE_DEFAULT_CHARSET         = "UTF-8";
61  
62      /***
63       * size used for nio header bytebuffers containing the size of the data buffers
64       */
65      public static final int    NIO_HEADER_SIZE              = 4;
66  
67      /***
68       * buffer size used for the bytbuffer outputstreams used by both client and server
69       */
70      public static final int    NIO_BYTEBUFFER_STREAM_SIZE   = 2048;
71  
72      /***
73       * buffer size used for the BufferedInputStream, BufferedOutputStream as well as for (De)Compression streams
74       */
75      public static final int    BUFFERED_STREAM_SIZE         = 4096;
76  
77      /***
78       * Default compression level used for compressing data with GZIP if enabled
79       */
80      public static final int    DEFAULT_COMPRESSION_LEVEL    = 4;
81  
82      /***
83       * number of trials for write/read data before a socketchannel will be marked as blocking
84       */
85      public static final int    NIO_MAX_ITERATIONS           = 10;
86  
87      /***
88       * Initially allocated size of the ByteBuffers used to read HTTP headers
89       */
90      public static final int    HTTP_BYTEBUFFER_PREALLOC     = 256;
91  
92      /***
93       * Default content type used for HTTP communications if the used SerializeAdapter doesn't indicate a supported
94       * content type or when direct byte buffer exchange is used
95       */
96      public static final String HTTP_DEFAULT_CONTENTTYPE     = "application/octet-stream";
97  
98      /***
99       * Name of the POST variable clients can use for sending HTTP packaged request
100      */
101     public static final String HTTP_PARAM_NAME              = "ejdata";
102 
103     /***
104      * the default port on which ejoe will bind the server socket
105      */
106     public static final int    EJOE_PORT                    = 12577;
107 
108     /***
109      * the default port on which ejoe will bind the server socket for remote classloading
110      */
111     public static final int    EJOE_CLASSLOADER_PORT        = 12578;
112 
113     /***
114      * the default amount of concurrent read and server handler operations EJOE will process simultaneously
115      */
116     public static final int    EJOE_MAX_READPROCESSORS      = 4;
117 
118     /***
119      * the default amount of concurrent socket write operations EJOE will process simultaneously
120      */
121     public static final int    EJOE_MAX_WRITEPROCESSORS     = 2;
122 
123     /***
124      * the timeout used when EJOE clients are waiting for server responses or vice versa
125      */
126     public static final int    EJOE_CONNECTION_TIMEOUT      = 30000;
127 
128     /***
129      * the timeout used when EJOE will block before next selection call if the last selection was zero
130      */
131     public static final int    EJOE_WAIT_TIMEOUT            = 50;
132 
133     /***
134      * max. supported TCP window size
135      */
136     public static final int    EJOE_MAX_SOCKET_BUF_SIZE     = 65536;
137 
138     /***
139      * the time period used for the ThreadPool resizer thread, which inspects the used ThreadPools and will resize them
140      * if neccessary
141      */
142     public static final int    EJOE_POOL_RESIZER_PERIOD     = 30000;
143 
144     /***
145      * the timeout used by the ThreadPool resizer thread. If the current pool size is too high or too low for all
146      * inspections done within the timeout, the resizer will try to resize the size of the inspected ThreadPool
147      */
148     public static final int    EJOE_POOL_RESIZER_SHRINKWAIT = 300000;
149 
150     /***
151      * Default mode: EJClient and EJServer will send and receive respectively serialize and deserialize objects with a
152      * SerializeAdapter. EJClient will return server responses as deserialized object instances.
153      */
154     public static final int    ADAPTER_STRATEGY_DEFAULT     = 0;
155 
156     /***
157      * Direct mode: EJClient and EJServer will just take ByteBuffers and exchange them directly without a
158      * SerializeAdapter.
159      */
160     public static final int    ADAPTER_STRATEGY_DIRECT      = 1;
161 
162     /***
163      * Mixed mode: EJClient and EJServer will send and receive respectively serialize and deserialize objects with a
164      * SerializeAdapter similiar to {@link EJClient#ADAPTER_STRATEGY_DEFAULT} but EJClient will not deserialize server
165      * responses to objects, it will just return the serialized representation of the response as written by the
166      * SerializeAdapter of EJServer. Hence if you use a xml based adapter EJClient will return the xml representation of
167      * the response.
168      */
169     public static final int    ADAPTER_STRATEGY_MIXED       = 2;
170 
171     /***
172      * default socket option
173      */
174     public final static int    IPTOS_THROUGHPUT             = 0x08;
175 
176     /***
177      * the Java version, eg. 1.4.2_08 or 1.5.0_06
178      */
179     public static final String JAVA_VERSION                 = System.getProperty( "java.version" );
180 
181     /***
182      * the Java version converted to int, eg. 1.4.2_08 = 142, 1.5.0_06 = 150
183      */
184     public static int          JAVA_VERSION_INT;
185 
186     static
187     {
188         try
189         {
190             // will throw ClassNotFoundException if XStream library is missing
191             new XStreamAdapter();
192             EJOE_DEFAULT_ADAPTER = de.netseeker.ejoe.adapter.XStreamAdapter.class;
193         }
194         catch ( Throwable e )
195         {
196             // XStream was not found on classpath
197             EJOE_DEFAULT_ADAPTER = ObjectStreamAdapter.class;
198         }
199 
200         if ( JAVA_VERSION != null )
201         {
202             for ( int i = 0; i < JAVA_VERSION.length(); i++ )
203             {
204                 char ch = JAVA_VERSION.charAt( i );
205                 if ( ch >= '0' && ch <= '9' )
206                 {
207                     String raw = JAVA_VERSION.substring( i );
208                     String str = raw.substring( 0, 1 );
209                     str = str + raw.substring( 2, 3 );
210                     if ( raw.length() >= 5 )
211                     {
212                         str = str + raw.substring( 4, 5 );
213                     }
214                     else
215                     {
216                         str = str + "0";
217                     }
218                     JAVA_VERSION_INT = Integer.parseInt( str );
219                     break;
220                 }
221             }
222         }
223     }
224 }