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 */ 017package org.apache.activemq.openwire; 018 019import org.apache.activemq.ActiveMQConnectionMetaData; 020import org.apache.activemq.command.WireFormatInfo; 021import org.apache.activemq.wireformat.WireFormat; 022import org.apache.activemq.wireformat.WireFormatFactory; 023 024/** 025 * 026 */ 027public class OpenWireFormatFactory implements WireFormatFactory { 028 029 // 030 // The default values here are what the wire format changes to after a 031 // default negotiation. 032 // 033 034 private int version = OpenWireFormat.DEFAULT_WIRE_VERSION; 035 private boolean stackTraceEnabled = true; 036 private boolean tcpNoDelayEnabled = true; 037 private boolean cacheEnabled = true; 038 private boolean tightEncodingEnabled = true; 039 private boolean sizePrefixDisabled; 040 private long maxInactivityDuration = 30*1000; 041 private long maxInactivityDurationInitalDelay = 10*1000; 042 private int cacheSize = 1024; 043 private long maxFrameSize = OpenWireFormat.DEFAULT_MAX_FRAME_SIZE; 044 private boolean maxFrameSizeEnabled = true; 045 private String host=null; 046 private String providerName = ActiveMQConnectionMetaData.PROVIDER_NAME; 047 private String providerVersion = ActiveMQConnectionMetaData.PROVIDER_VERSION; 048 private String platformDetails = ActiveMQConnectionMetaData.DEFAULT_PLATFORM_DETAILS; 049 private boolean includePlatformDetails = false; 050 051 @Override 052 public WireFormat createWireFormat() { 053 WireFormatInfo info = new WireFormatInfo(); 054 info.setVersion(version); 055 056 try { 057 info.setStackTraceEnabled(stackTraceEnabled); 058 info.setCacheEnabled(cacheEnabled); 059 info.setTcpNoDelayEnabled(tcpNoDelayEnabled); 060 info.setTightEncodingEnabled(tightEncodingEnabled); 061 info.setSizePrefixDisabled(sizePrefixDisabled); 062 info.setMaxInactivityDuration(maxInactivityDuration); 063 info.setMaxInactivityDurationInitalDelay(maxInactivityDurationInitalDelay); 064 info.setCacheSize(cacheSize); 065 info.setMaxFrameSize(maxFrameSize); 066 info.setMaxFrameSizeEnabled(maxFrameSizeEnabled); 067 if( host!=null ) { 068 info.setHost(host); 069 } 070 info.setProviderName(providerName); 071 info.setProviderVersion(providerVersion); 072 if (includePlatformDetails) { 073 platformDetails = ActiveMQConnectionMetaData.PLATFORM_DETAILS; 074 } 075 info.setPlatformDetails(platformDetails); 076 } catch (Exception e) { 077 IllegalStateException ise = new IllegalStateException("Could not configure WireFormatInfo"); 078 ise.initCause(e); 079 throw ise; 080 } 081 082 OpenWireFormat f = new OpenWireFormat(version); 083 f.setMaxFrameSize(maxFrameSize); 084 f.setPreferedWireFormatInfo(info); 085 f.setMaxFrameSizeEnabled(maxFrameSizeEnabled); 086 return f; 087 } 088 089 public boolean isStackTraceEnabled() { 090 return stackTraceEnabled; 091 } 092 093 public void setStackTraceEnabled(boolean stackTraceEnabled) { 094 this.stackTraceEnabled = stackTraceEnabled; 095 } 096 097 public boolean isTcpNoDelayEnabled() { 098 return tcpNoDelayEnabled; 099 } 100 101 public void setTcpNoDelayEnabled(boolean tcpNoDelayEnabled) { 102 this.tcpNoDelayEnabled = tcpNoDelayEnabled; 103 } 104 105 public int getVersion() { 106 return version; 107 } 108 109 public void setVersion(int version) { 110 this.version = version; 111 } 112 113 public boolean isCacheEnabled() { 114 return cacheEnabled; 115 } 116 117 public void setCacheEnabled(boolean cacheEnabled) { 118 this.cacheEnabled = cacheEnabled; 119 } 120 121 public boolean isTightEncodingEnabled() { 122 return tightEncodingEnabled; 123 } 124 125 public void setTightEncodingEnabled(boolean tightEncodingEnabled) { 126 this.tightEncodingEnabled = tightEncodingEnabled; 127 } 128 129 public boolean isSizePrefixDisabled() { 130 return sizePrefixDisabled; 131 } 132 133 public void setSizePrefixDisabled(boolean sizePrefixDisabled) { 134 this.sizePrefixDisabled = sizePrefixDisabled; 135 } 136 137 public long getMaxInactivityDuration() { 138 return maxInactivityDuration; 139 } 140 141 public void setMaxInactivityDuration(long maxInactivityDuration) { 142 this.maxInactivityDuration = maxInactivityDuration; 143 } 144 145 public int getCacheSize() { 146 return cacheSize; 147 } 148 149 public void setCacheSize(int cacheSize) { 150 this.cacheSize = cacheSize; 151 } 152 153 public long getMaxInactivityDurationInitalDelay() { 154 return maxInactivityDurationInitalDelay; 155 } 156 157 public void setMaxInactivityDurationInitalDelay( 158 long maxInactivityDurationInitalDelay) { 159 this.maxInactivityDurationInitalDelay = maxInactivityDurationInitalDelay; 160 } 161 162 public long getMaxFrameSize() { 163 return maxFrameSize; 164 } 165 166 public void setMaxFrameSize(long maxFrameSize) { 167 this.maxFrameSize = maxFrameSize; 168 } 169 170 public String getHost() { 171 return host; 172 } 173 174 public void setHost(String host) { 175 this.host = host; 176 } 177 178 public String getProviderName() { 179 return providerName; 180 } 181 182 public void setProviderName(String providerName) { 183 this.providerName = providerName; 184 } 185 186 public String getProviderVersion() { 187 return providerVersion; 188 } 189 190 public void setProviderVersion(String providerVersion) { 191 this.providerVersion = providerVersion; 192 } 193 194 public String getPlatformDetails() { 195 return platformDetails; 196 } 197 198 public void setPlatformDetails(String platformDetails) { 199 this.platformDetails = platformDetails; 200 } 201 202 public boolean isIncludePlatformDetails() { 203 return includePlatformDetails; 204 } 205 206 public void setIncludePlatformDetails(boolean includePlatformDetails) { 207 this.includePlatformDetails = includePlatformDetails; 208 } 209 210 /** 211 * Set whether the maxFrameSize check will be enabled. Note this is only applied to this factory 212 * and will NOT be negotiated 213 * 214 * @param maxFrameSizeEnabled 215 */ 216 public void setMaxFrameSizeEnabled(boolean maxFrameSizeEnabled) { 217 this.maxFrameSizeEnabled = maxFrameSizeEnabled; 218 } 219 220 public boolean isMaxFrameSizeEnabled() { 221 return this.maxFrameSizeEnabled; 222 } 223}