1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with 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, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.mina.transport.socket; 21 22 import org.apache.mina.core.session.AbstractIoSessionConfig; 23 import org.apache.mina.core.session.IoSessionConfig; 24 25 /** 26 * TODO Add documentation 27 * 28 * @author <a href="http://mina.apache.org">Apache MINA Project</a> 29 */ 30 public abstract class AbstractDatagramSessionConfig extends 31 AbstractIoSessionConfig implements DatagramSessionConfig { 32 33 private static final boolean DEFAULT_CLOSE_ON_PORT_UNREACHABLE = true; 34 35 private boolean closeOnPortUnreachable = DEFAULT_CLOSE_ON_PORT_UNREACHABLE; 36 37 protected AbstractDatagramSessionConfig() { 38 // Do nothing 39 } 40 41 @Override 42 protected void doSetAll(IoSessionConfig config) { 43 if (!(config instanceof DatagramSessionConfig)) { 44 return; 45 } 46 47 if (config instanceof AbstractDatagramSessionConfig) { 48 // Minimize unnecessary system calls by checking all 'propertyChanged' properties. 49 AbstractDatagramSessionConfig cfg = (AbstractDatagramSessionConfig) config; 50 if (cfg.isBroadcastChanged()) { 51 setBroadcast(cfg.isBroadcast()); 52 } 53 if (cfg.isReceiveBufferSizeChanged()) { 54 setReceiveBufferSize(cfg.getReceiveBufferSize()); 55 } 56 if (cfg.isReuseAddressChanged()) { 57 setReuseAddress(cfg.isReuseAddress()); 58 } 59 if (cfg.isSendBufferSizeChanged()) { 60 setSendBufferSize(cfg.getSendBufferSize()); 61 } 62 if (cfg.isTrafficClassChanged() && getTrafficClass() != cfg.getTrafficClass()) { 63 setTrafficClass(cfg.getTrafficClass()); 64 } 65 } else { 66 DatagramSessionConfig cfg = (DatagramSessionConfig) config; 67 setBroadcast(cfg.isBroadcast()); 68 setReceiveBufferSize(cfg.getReceiveBufferSize()); 69 setReuseAddress(cfg.isReuseAddress()); 70 setSendBufferSize(cfg.getSendBufferSize()); 71 if (getTrafficClass() != cfg.getTrafficClass()) { 72 setTrafficClass(cfg.getTrafficClass()); 73 } 74 } 75 } 76 77 /** 78 * Returns <tt>true</tt> if and only if the <tt>broadcast</tt> property 79 * has been changed by its setter method. The system call related with 80 * the property is made only when this method returns <tt>true</tt>. By 81 * default, this method always returns <tt>true</tt> to simplify implementation 82 * of subclasses, but overriding the default behavior is always encouraged. 83 */ 84 protected boolean isBroadcastChanged() { 85 return true; 86 } 87 88 /** 89 * Returns <tt>true</tt> if and only if the <tt>receiveBufferSize</tt> property 90 * has been changed by its setter method. The system call related with 91 * the property is made only when this method returns <tt>true</tt>. By 92 * default, this method always returns <tt>true</tt> to simplify implementation 93 * of subclasses, but overriding the default behavior is always encouraged. 94 */ 95 protected boolean isReceiveBufferSizeChanged() { 96 return true; 97 } 98 99 /** 100 * Returns <tt>true</tt> if and only if the <tt>reuseAddress</tt> property 101 * has been changed by its setter method. The system call related with 102 * the property is made only when this method returns <tt>true</tt>. By 103 * default, this method always returns <tt>true</tt> to simplify implementation 104 * of subclasses, but overriding the default behavior is always encouraged. 105 */ 106 protected boolean isReuseAddressChanged() { 107 return true; 108 } 109 110 /** 111 * Returns <tt>true</tt> if and only if the <tt>sendBufferSize</tt> property 112 * has been changed by its setter method. The system call related with 113 * the property is made only when this method returns <tt>true</tt>. By 114 * default, this method always returns <tt>true</tt> to simplify implementation 115 * of subclasses, but overriding the default behavior is always encouraged. 116 */ 117 protected boolean isSendBufferSizeChanged() { 118 return true; 119 } 120 121 /** 122 * Returns <tt>true</tt> if and only if the <tt>trafficClass</tt> property 123 * has been changed by its setter method. The system call related with 124 * the property is made only when this method returns <tt>true</tt>. By 125 * default, this method always returns <tt>true</tt> to simplify implementation 126 * of subclasses, but overriding the default behavior is always encouraged. 127 */ 128 protected boolean isTrafficClassChanged() { 129 return true; 130 } 131 132 /** 133 * {@inheritDoc} 134 */ 135 public boolean isCloseOnPortUnreachable() { 136 return closeOnPortUnreachable; 137 } 138 139 /** 140 * {@inheritDoc} 141 */ 142 public void setCloseOnPortUnreachable(boolean closeOnPortUnreachable) { 143 this.closeOnPortUnreachable = closeOnPortUnreachable; 144 } 145 }