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 String host=null; 045 private String providerName = ActiveMQConnectionMetaData.PROVIDER_NAME; 046 private String providerVersion = ActiveMQConnectionMetaData.PROVIDER_VERSION; 047 private String platformDetails = ActiveMQConnectionMetaData.DEFAULT_PLATFORM_DETAILS; 048 private boolean includePlatformDetails = false; 049 050 @Override 051 public WireFormat createWireFormat() { 052 WireFormatInfo info = new WireFormatInfo(); 053 info.setVersion(version); 054 055 try { 056 info.setStackTraceEnabled(stackTraceEnabled); 057 info.setCacheEnabled(cacheEnabled); 058 info.setTcpNoDelayEnabled(tcpNoDelayEnabled); 059 info.setTightEncodingEnabled(tightEncodingEnabled); 060 info.setSizePrefixDisabled(sizePrefixDisabled); 061 info.setMaxInactivityDuration(maxInactivityDuration); 062 info.setMaxInactivityDurationInitalDelay(maxInactivityDurationInitalDelay); 063 info.setCacheSize(cacheSize); 064 info.setMaxFrameSize(maxFrameSize); 065 if( host!=null ) { 066 info.setHost(host); 067 } 068 info.setProviderName(providerName); 069 info.setProviderVersion(providerVersion); 070 if (includePlatformDetails) { 071 platformDetails = ActiveMQConnectionMetaData.PLATFORM_DETAILS; 072 } 073 info.setPlatformDetails(platformDetails); 074 } catch (Exception e) { 075 IllegalStateException ise = new IllegalStateException("Could not configure WireFormatInfo"); 076 ise.initCause(e); 077 throw ise; 078 } 079 080 OpenWireFormat f = new OpenWireFormat(version); 081 f.setMaxFrameSize(maxFrameSize); 082 f.setPreferedWireFormatInfo(info); 083 return f; 084 } 085 086 public boolean isStackTraceEnabled() { 087 return stackTraceEnabled; 088 } 089 090 public void setStackTraceEnabled(boolean stackTraceEnabled) { 091 this.stackTraceEnabled = stackTraceEnabled; 092 } 093 094 public boolean isTcpNoDelayEnabled() { 095 return tcpNoDelayEnabled; 096 } 097 098 public void setTcpNoDelayEnabled(boolean tcpNoDelayEnabled) { 099 this.tcpNoDelayEnabled = tcpNoDelayEnabled; 100 } 101 102 public int getVersion() { 103 return version; 104 } 105 106 public void setVersion(int version) { 107 this.version = version; 108 } 109 110 public boolean isCacheEnabled() { 111 return cacheEnabled; 112 } 113 114 public void setCacheEnabled(boolean cacheEnabled) { 115 this.cacheEnabled = cacheEnabled; 116 } 117 118 public boolean isTightEncodingEnabled() { 119 return tightEncodingEnabled; 120 } 121 122 public void setTightEncodingEnabled(boolean tightEncodingEnabled) { 123 this.tightEncodingEnabled = tightEncodingEnabled; 124 } 125 126 public boolean isSizePrefixDisabled() { 127 return sizePrefixDisabled; 128 } 129 130 public void setSizePrefixDisabled(boolean sizePrefixDisabled) { 131 this.sizePrefixDisabled = sizePrefixDisabled; 132 } 133 134 public long getMaxInactivityDuration() { 135 return maxInactivityDuration; 136 } 137 138 public void setMaxInactivityDuration(long maxInactivityDuration) { 139 this.maxInactivityDuration = maxInactivityDuration; 140 } 141 142 public int getCacheSize() { 143 return cacheSize; 144 } 145 146 public void setCacheSize(int cacheSize) { 147 this.cacheSize = cacheSize; 148 } 149 150 public long getMaxInactivityDurationInitalDelay() { 151 return maxInactivityDurationInitalDelay; 152 } 153 154 public void setMaxInactivityDurationInitalDelay( 155 long maxInactivityDurationInitalDelay) { 156 this.maxInactivityDurationInitalDelay = maxInactivityDurationInitalDelay; 157 } 158 159 public long getMaxFrameSize() { 160 return maxFrameSize; 161 } 162 163 public void setMaxFrameSize(long maxFrameSize) { 164 this.maxFrameSize = maxFrameSize; 165 } 166 167 public String getHost() { 168 return host; 169 } 170 171 public void setHost(String host) { 172 this.host = host; 173 } 174 175 public String getProviderName() { 176 return providerName; 177 } 178 179 public void setProviderName(String providerName) { 180 this.providerName = providerName; 181 } 182 183 public String getProviderVersion() { 184 return providerVersion; 185 } 186 187 public void setProviderVersion(String providerVersion) { 188 this.providerVersion = providerVersion; 189 } 190 191 public String getPlatformDetails() { 192 return platformDetails; 193 } 194 195 public void setPlatformDetails(String platformDetails) { 196 this.platformDetails = platformDetails; 197 } 198 199 public boolean isIncludePlatformDetails() { 200 return includePlatformDetails; 201 } 202 203 public void setIncludePlatformDetails(boolean includePlatformDetails) { 204 this.includePlatformDetails = includePlatformDetails; 205 } 206}