001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 *
019 */
020package org.apache.mina.transport.socket;
021
022import java.net.DatagramSocket;
023
024/**
025 * A default implementation of {@link DatagramSessionConfig}.
026 *
027 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
028 */
029public class DefaultDatagramSessionConfig extends AbstractDatagramSessionConfig {
030    private static final boolean DEFAULT_BROADCAST = false;
031
032    private static final boolean DEFAULT_REUSE_ADDRESS = false;
033
034    /* The SO_RCVBUF parameter. Set to -1 (ie, will default to OS default) */
035    private static final int DEFAULT_RECEIVE_BUFFER_SIZE = -1;
036
037    /* The SO_SNDBUF parameter. Set to -1 (ie, will default to OS default) */
038    private static final int DEFAULT_SEND_BUFFER_SIZE = -1;
039
040    private static final int DEFAULT_TRAFFIC_CLASS = 0;
041
042    private boolean broadcast = DEFAULT_BROADCAST;
043
044    private boolean reuseAddress = DEFAULT_REUSE_ADDRESS;
045
046    private int receiveBufferSize = DEFAULT_RECEIVE_BUFFER_SIZE;
047
048    private int sendBufferSize = DEFAULT_SEND_BUFFER_SIZE;
049
050    private int trafficClass = DEFAULT_TRAFFIC_CLASS;
051
052    /**
053     * Creates a new instance.
054     */
055    public DefaultDatagramSessionConfig() {
056        // Do nothing
057    }
058
059    /**
060     * @see DatagramSocket#getBroadcast()
061     */
062    public boolean isBroadcast() {
063        return broadcast;
064    }
065
066    /**
067     * @see DatagramSocket#setBroadcast(boolean)
068     */
069    public void setBroadcast(boolean broadcast) {
070        this.broadcast = broadcast;
071    }
072
073    /**
074     * @see DatagramSocket#getReuseAddress()
075     */
076    public boolean isReuseAddress() {
077        return reuseAddress;
078    }
079
080    /**
081     * @see DatagramSocket#setReuseAddress(boolean)
082     */
083    public void setReuseAddress(boolean reuseAddress) {
084        this.reuseAddress = reuseAddress;
085    }
086
087    /**
088     * @see DatagramSocket#getReceiveBufferSize()
089     */
090    public int getReceiveBufferSize() {
091        return receiveBufferSize;
092    }
093
094    /**
095     * @see DatagramSocket#setReceiveBufferSize(int)
096     */
097    public void setReceiveBufferSize(int receiveBufferSize) {
098        this.receiveBufferSize = receiveBufferSize;
099    }
100
101    /**
102     * @see DatagramSocket#getSendBufferSize()
103     */
104    public int getSendBufferSize() {
105        return sendBufferSize;
106    }
107
108    /**
109     * @see DatagramSocket#setSendBufferSize(int)
110     */
111    public void setSendBufferSize(int sendBufferSize) {
112        this.sendBufferSize = sendBufferSize;
113    }
114
115    /**
116     * @see DatagramSocket#getTrafficClass()
117     */
118    public int getTrafficClass() {
119        return trafficClass;
120    }
121
122    /**
123     * @see DatagramSocket#setTrafficClass(int)
124     */
125    public void setTrafficClass(int trafficClass) {
126        this.trafficClass = trafficClass;
127    }
128
129    @Override
130    protected boolean isBroadcastChanged() {
131        return broadcast != DEFAULT_BROADCAST;
132    }
133
134    @Override
135    protected boolean isReceiveBufferSizeChanged() {
136        return receiveBufferSize != DEFAULT_RECEIVE_BUFFER_SIZE;
137    }
138
139    @Override
140    protected boolean isReuseAddressChanged() {
141        return reuseAddress != DEFAULT_REUSE_ADDRESS;
142    }
143
144    @Override
145    protected boolean isSendBufferSizeChanged() {
146        return sendBufferSize != DEFAULT_SEND_BUFFER_SIZE;
147    }
148
149    @Override
150    protected boolean isTrafficClassChanged() {
151        return trafficClass != DEFAULT_TRAFFIC_CLASS;
152    }
153
154}