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