KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > openwire > OpenWireFormatFactory


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.openwire;
19
20 import org.apache.activemq.command.WireFormatInfo;
21 import org.apache.activemq.wireformat.WireFormat;
22 import org.apache.activemq.wireformat.WireFormatFactory;
23
24 /**
25  * @version $Revision$
26  */

27 public class OpenWireFormatFactory implements WireFormatFactory {
28
29     //
30
// The default values here are what the wire format changes to after a default negotiation.
31
//
32

33     private int version=OpenWireFormat.DEFAULT_VERSION;
34     private boolean stackTraceEnabled=true;
35     private boolean tcpNoDelayEnabled=true;
36     private boolean cacheEnabled=true;
37     private boolean tightEncodingEnabled=true;
38     private boolean sizePrefixDisabled=false;
39     private long maxInactivityDuration=30*1000;
40     private int cacheSize=1024;
41     
42     public WireFormat createWireFormat() {
43         WireFormatInfo info = new WireFormatInfo();
44         info.setVersion(version);
45         
46         try {
47             info.setStackTraceEnabled(stackTraceEnabled);
48             info.setCacheEnabled(cacheEnabled);
49             info.setTcpNoDelayEnabled(tcpNoDelayEnabled);
50             info.setTightEncodingEnabled(tightEncodingEnabled);
51             info.setSizePrefixDisabled(sizePrefixDisabled);
52             info.seMaxInactivityDuration(maxInactivityDuration);
53             info.setCacheSize(cacheSize);
54         } catch (Exception JavaDoc e) {
55             IllegalStateException JavaDoc ise = new IllegalStateException JavaDoc("Could not configure WireFormatInfo");
56             ise.initCause(e);
57             throw ise;
58         }
59         
60         OpenWireFormat f = new OpenWireFormat();
61         f.setPreferedWireFormatInfo(info);
62         return f;
63     }
64
65     public boolean isStackTraceEnabled() {
66         return stackTraceEnabled;
67     }
68
69     public void setStackTraceEnabled(boolean stackTraceEnabled) {
70         this.stackTraceEnabled = stackTraceEnabled;
71     }
72
73     public boolean isTcpNoDelayEnabled() {
74         return tcpNoDelayEnabled;
75     }
76
77     public void setTcpNoDelayEnabled(boolean tcpNoDelayEnabled) {
78         this.tcpNoDelayEnabled = tcpNoDelayEnabled;
79     }
80
81     public int getVersion() {
82         return version;
83     }
84
85     public void setVersion(int version) {
86         this.version = version;
87     }
88
89     public boolean isCacheEnabled() {
90         return cacheEnabled;
91     }
92
93     public void setCacheEnabled(boolean cacheEnabled) {
94         this.cacheEnabled = cacheEnabled;
95     }
96
97     public boolean isTightEncodingEnabled() {
98         return tightEncodingEnabled;
99     }
100
101     public void setTightEncodingEnabled(boolean tightEncodingEnabled) {
102         this.tightEncodingEnabled = tightEncodingEnabled;
103     }
104
105     public boolean isSizePrefixDisabled() {
106         return sizePrefixDisabled;
107     }
108
109     public void setSizePrefixDisabled(boolean sizePrefixDisabled) {
110         this.sizePrefixDisabled = sizePrefixDisabled;
111     }
112
113     public long getMaxInactivityDuration() {
114         return maxInactivityDuration;
115     }
116
117     public void setMaxInactivityDuration(long maxInactivityDuration) {
118         this.maxInactivityDuration = maxInactivityDuration;
119     }
120
121     public int getCacheSize() {
122         return cacheSize;
123     }
124
125     public void setCacheSize(int cacheSize) {
126         this.cacheSize = cacheSize;
127     }
128 }
129
Popular Tags