PageRenderTime 18ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/hazelcast/src/main/java/com/hazelcast/config/QueueConfig.java

https://bitbucket.org/gabral6_gmailcom/hazelcast
Java | 132 lines | 83 code | 21 blank | 28 comment | 10 complexity | 6ee0b0dbe7678dda75724e95f407d017 MD5 | raw file
  1/*
  2 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
  3 *
  4 * Licensed under the Apache License, Version 2.0 (the "License");
  5 * you may not use this file except in compliance with the License.
  6 * You may obtain a copy of the License at
  7 *
  8 * http://www.apache.org/licenses/LICENSE-2.0
  9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed under the License is distributed on an "AS IS" BASIS,
 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13 * See the License for the specific language governing permissions and
 14 * limitations under the License.
 15 */
 16
 17package com.hazelcast.config;
 18
 19import com.hazelcast.nio.DataSerializable;
 20
 21import java.io.DataInput;
 22import java.io.DataOutput;
 23import java.io.IOException;
 24import java.util.ArrayList;
 25import java.util.List;
 26
 27public final class QueueConfig implements DataSerializable {
 28
 29    public final static int DEFAULT_MAX_SIZE_PER_JVM = 0;
 30
 31    private String name;
 32    private String backingMapRef;
 33    private int maxSizePerJVM = DEFAULT_MAX_SIZE_PER_JVM;
 34    private List<ItemListenerConfig> listenerConfigs;
 35
 36    public QueueConfig() {
 37    }
 38
 39    public QueueConfig(QueueConfig config) {
 40        this.name = config.name;
 41        this.backingMapRef = config.backingMapRef;
 42        this.maxSizePerJVM = config.maxSizePerJVM;
 43    }
 44
 45    /**
 46     * @return the name
 47     */
 48    public String getName() {
 49        return name;
 50    }
 51
 52    /**
 53     * @param name the name to set
 54     * @return this queue config
 55     */
 56    public QueueConfig setName(String name) {
 57        this.name = name;
 58        if (backingMapRef == null) {
 59            backingMapRef = "q:" + name;
 60        }
 61        return this;
 62    }
 63
 64    /**
 65     * @return the maxSizePerJVM
 66     */
 67    public int getMaxSizePerJVM() {
 68        return maxSizePerJVM;
 69    }
 70
 71    /**
 72     * @param maxSizePerJVM the maxSizePerJVM to set
 73     */
 74    public QueueConfig setMaxSizePerJVM(int maxSizePerJVM) {
 75        if (maxSizePerJVM < 0) {
 76            throw new IllegalArgumentException("queue max size per JVM must be positive");
 77        }
 78        this.maxSizePerJVM = maxSizePerJVM;
 79        return this;
 80    }
 81
 82    public String getBackingMapRef() {
 83        return backingMapRef;
 84    }
 85
 86    public QueueConfig setBackingMapRef(String backingMapRef) {
 87        this.backingMapRef = backingMapRef;
 88        return this;
 89    }
 90
 91    public QueueConfig addItemListenerConfig(ItemListenerConfig listenerConfig) {
 92        getItemListenerConfigs().add(listenerConfig);
 93        return this;
 94    }
 95
 96    public List<ItemListenerConfig> getItemListenerConfigs() {
 97        if (listenerConfigs == null) {
 98            listenerConfigs = new ArrayList<ItemListenerConfig>();
 99        }
100        return listenerConfigs;
101    }
102
103    public void setItemListenerConfigs(List<ItemListenerConfig> listenerConfigs) {
104        this.listenerConfigs = listenerConfigs;
105    }
106
107    public boolean isCompatible(final QueueConfig queueConfig) {
108        if (queueConfig == null) return false;
109        return (name != null ? name.equals(queueConfig.name) : queueConfig.name == null) &&
110                this.backingMapRef.equals(queueConfig.backingMapRef) &&
111                this.maxSizePerJVM == queueConfig.maxSizePerJVM;
112    }
113
114    public void writeData(DataOutput out) throws IOException {
115        out.writeUTF(name);
116        out.writeUTF(backingMapRef);
117        out.writeInt(maxSizePerJVM);
118    }
119
120    public void readData(DataInput in) throws IOException {
121        name = in.readUTF();
122        backingMapRef = in.readUTF();
123        maxSizePerJVM = in.readInt();
124    }
125
126    @Override
127    public String toString() {
128        return "QueueConfig [name=" + this.name
129                + ", backingMapRef=" + this.backingMapRef
130                + ", maxSizePerJVM=" + this.maxSizePerJVM + "]";
131    }
132}