/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.activeblaze;

import org.apache.activeblaze.util.PropertyUtil;

import java.util.Map;

/**
 * Basic Configuration for a BlazeChannel
 */
public class BlazeConfiguration {
    /**
     * Max size for datagrams
     */
    public static final int DEFAULT_MAX_PACKET_SIZE = 4 * 1024;
    // transport bindings
    private int unicastPort = 0;
    private String broadcastURI = "mcast://224.2.2.2:9999";
    private String managementURI = "";
    private int maxDispatchQueueSize = 10000;
    private int maxPacketSize = DEFAULT_MAX_PACKET_SIZE;
    // reliability
    private String reliableBroadcast = "simple";

    /**
     * @return the unicastPort
     */
    public int getUnicastPort() {
        return this.unicastPort;
    }

    /**
     * @param unicastPort the unicastPort to set
     */
    public void setUnicastPort(int unicastPort) {
        this.unicastPort = unicastPort;
    }

    /**
     * @return the broadcastURL
     */
    public String getBroadcastURI() {
        return this.broadcastURI;
    }

    /**
     * @param broadcastURL the broadcastURL to set
     */
    public void setBroadcastURI(String broadcastURL) {
        this.broadcastURI = broadcastURL;
    }

    /**
     * @return the maxDispatchQueueSize
     */
    public int getMaxDispatchQueueSize() {
        return this.maxDispatchQueueSize;
    }

    /**
     * @param maxDispatchQueueSize the maxDispatchQueueSize to set
     */
    public void setMaxDispatchQueueSize(int maxDispatchQueueSize) {
        this.maxDispatchQueueSize = maxDispatchQueueSize;
    }

    /**
     * @return the managmentURI
     */
    public String getManagementURI() {
        return this.managementURI;
    }

    /**
     * @param managementURI the managementURI to set
     */
    public void setManagementURI(String managementURI) {
        this.managementURI = managementURI;
    }

    /**
     * @return the maxPacketSize
     */
    public int getMaxPacketSize() {
        return this.maxPacketSize;
    }

    /**
     * @param maxPacketSize the maxPacketSize to set
     */
    public void setMaxPacketSize(int maxPacketSize) {
        this.maxPacketSize = maxPacketSize;
    }

    /**
     * Copy the configuration
     *
     * @return a deep copy of the configuration
     */
    public final BlazeConfiguration copy() throws Exception {
        Map<String, String> props = PropertyUtil.getProperties(this);
        BlazeConfiguration result = newInstance();
        PropertyUtil.setProperties(result, props);
        return result;
    }

    protected BlazeConfiguration newInstance() {
        return new BlazeConfiguration();
    }

    /**
     * @return the reliable
     */
    public String getReliableBroadcast() {
        return this.reliableBroadcast;
    }

    /**
     * @param reliable the reliable to set
     */
    public void setReliableBroadcast(String reliable) {
        this.reliableBroadcast = reliable;
    }
}
