/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. package com.hazelcast.config;
  17. import com.hazelcast.nio.DataSerializable;
  18. import java.io.DataInput;
  19. import java.io.DataOutput;
  20. import java.io.IOException;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. public final class QueueConfig implements DataSerializable {
  24. public final static int DEFAULT_MAX_SIZE_PER_JVM = 0;
  25. private String name;
  26. private String backingMapRef;
  27. private int maxSizePerJVM = DEFAULT_MAX_SIZE_PER_JVM;
  28. private List<ItemListenerConfig> listenerConfigs;
  29. public QueueConfig() {
  30. }
  31. public QueueConfig(QueueConfig config) {
  32. this.name = config.name;
  33. this.backingMapRef = config.backingMapRef;
  34. this.maxSizePerJVM = config.maxSizePerJVM;
  35. }
  36. /**
  37. * @return the name
  38. */
  39. public String getName() {
  40. return name;
  41. }
  42. /**
  43. * @param name the name to set
  44. * @return this queue config
  45. */
  46. public QueueConfig setName(String name) {
  47. this.name = name;
  48. if (backingMapRef == null) {
  49. backingMapRef = "q:" + name;
  50. }
  51. return this;
  52. }
  53. /**
  54. * @return the maxSizePerJVM
  55. */
  56. public int getMaxSizePerJVM() {
  57. return maxSizePerJVM;
  58. }
  59. /**
  60. * @param maxSizePerJVM the maxSizePerJVM to set
  61. */
  62. public QueueConfig setMaxSizePerJVM(int maxSizePerJVM) {
  63. if (maxSizePerJVM < 0) {
  64. throw new IllegalArgumentException("queue max size per JVM must be positive");
  65. }
  66. this.maxSizePerJVM = maxSizePerJVM;
  67. return this;
  68. }
  69. public String getBackingMapRef() {
  70. return backingMapRef;
  71. }
  72. public QueueConfig setBackingMapRef(String backingMapRef) {
  73. this.backingMapRef = backingMapRef;
  74. return this;
  75. }
  76. public QueueConfig addItemListenerConfig(ItemListenerConfig listenerConfig) {
  77. getItemListenerConfigs().add(listenerConfig);
  78. return this;
  79. }
  80. public List<ItemListenerConfig> getItemListenerConfigs() {
  81. if (listenerConfigs == null) {
  82. listenerConfigs = new ArrayList<ItemListenerConfig>();
  83. }
  84. return listenerConfigs;
  85. }
  86. public void setItemListenerConfigs(List<ItemListenerConfig> listenerConfigs) {
  87. this.listenerConfigs = listenerConfigs;
  88. }
  89. public boolean isCompatible(final QueueConfig queueConfig) {
  90. if (queueConfig == null) return false;
  91. return (name != null ? name.equals(queueConfig.name) : queueConfig.name == null) &&
  92. this.backingMapRef.equals(queueConfig.backingMapRef) &&
  93. this.maxSizePerJVM == queueConfig.maxSizePerJVM;
  94. }
  95. public void writeData(DataOutput out) throws IOException {
  96. out.writeUTF(name);
  97. out.writeUTF(backingMapRef);
  98. out.writeInt(maxSizePerJVM);
  99. }
  100. public void readData(DataInput in) throws IOException {
  101. name = in.readUTF();
  102. backingMapRef = in.readUTF();
  103. maxSizePerJVM = in.readInt();
  104. }
  105. @Override
  106. public String toString() {
  107. return "QueueConfig [name=" + this.name
  108. + ", backingMapRef=" + this.backingMapRef
  109. + ", maxSizePerJVM=" + this.maxSizePerJVM + "]";
  110. }
  111. }