001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.activemq.openwire; 018 019 import org.apache.activemq.command.WireFormatInfo; 020 import org.apache.activemq.wireformat.WireFormat; 021 import org.apache.activemq.wireformat.WireFormatFactory; 022 023 /** 024 * @version $Revision$ 025 */ 026 public class OpenWireFormatFactory implements WireFormatFactory { 027 028 // 029 // The default values here are what the wire format changes to after a 030 // default negotiation. 031 // 032 033 private int version = OpenWireFormat.DEFAULT_VERSION; 034 private boolean stackTraceEnabled = true; 035 private boolean tcpNoDelayEnabled = true; 036 private boolean cacheEnabled = true; 037 private boolean tightEncodingEnabled = true; 038 private boolean sizePrefixDisabled; 039 private long maxInactivityDuration = 30*1000; 040 private long maxInactivityDurationInitalDelay = 10*1000; 041 private int cacheSize = 1024; 042 043 public WireFormat createWireFormat() { 044 WireFormatInfo info = new WireFormatInfo(); 045 info.setVersion(version); 046 047 try { 048 info.setStackTraceEnabled(stackTraceEnabled); 049 info.setCacheEnabled(cacheEnabled); 050 info.setTcpNoDelayEnabled(tcpNoDelayEnabled); 051 info.setTightEncodingEnabled(tightEncodingEnabled); 052 info.setSizePrefixDisabled(sizePrefixDisabled); 053 info.setMaxInactivityDuration(maxInactivityDuration); 054 info.setMaxInactivityDurationInitalDelay(maxInactivityDurationInitalDelay); 055 info.setCacheSize(cacheSize); 056 } catch (Exception e) { 057 IllegalStateException ise = new IllegalStateException("Could not configure WireFormatInfo"); 058 ise.initCause(e); 059 throw ise; 060 } 061 062 OpenWireFormat f = new OpenWireFormat(); 063 f.setPreferedWireFormatInfo(info); 064 return f; 065 } 066 067 public boolean isStackTraceEnabled() { 068 return stackTraceEnabled; 069 } 070 071 public void setStackTraceEnabled(boolean stackTraceEnabled) { 072 this.stackTraceEnabled = stackTraceEnabled; 073 } 074 075 public boolean isTcpNoDelayEnabled() { 076 return tcpNoDelayEnabled; 077 } 078 079 public void setTcpNoDelayEnabled(boolean tcpNoDelayEnabled) { 080 this.tcpNoDelayEnabled = tcpNoDelayEnabled; 081 } 082 083 public int getVersion() { 084 return version; 085 } 086 087 public void setVersion(int version) { 088 this.version = version; 089 } 090 091 public boolean isCacheEnabled() { 092 return cacheEnabled; 093 } 094 095 public void setCacheEnabled(boolean cacheEnabled) { 096 this.cacheEnabled = cacheEnabled; 097 } 098 099 public boolean isTightEncodingEnabled() { 100 return tightEncodingEnabled; 101 } 102 103 public void setTightEncodingEnabled(boolean tightEncodingEnabled) { 104 this.tightEncodingEnabled = tightEncodingEnabled; 105 } 106 107 public boolean isSizePrefixDisabled() { 108 return sizePrefixDisabled; 109 } 110 111 public void setSizePrefixDisabled(boolean sizePrefixDisabled) { 112 this.sizePrefixDisabled = sizePrefixDisabled; 113 } 114 115 public long getMaxInactivityDuration() { 116 return maxInactivityDuration; 117 } 118 119 public void setMaxInactivityDuration(long maxInactivityDuration) { 120 this.maxInactivityDuration = maxInactivityDuration; 121 } 122 123 public int getCacheSize() { 124 return cacheSize; 125 } 126 127 public void setCacheSize(int cacheSize) { 128 this.cacheSize = cacheSize; 129 } 130 131 public long getMaxInactivityDurationInitalDelay() { 132 return maxInactivityDurationInitalDelay; 133 } 134 135 public void setMaxInactivityDurationInitalDelay( 136 long maxInactivityDurationInitalDelay) { 137 this.maxInactivityDurationInitalDelay = maxInactivityDurationInitalDelay; 138 } 139 }