001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.messaging;
016    
017    import com.liferay.portal.kernel.concurrent.RejectedExecutionHandler;
018    import com.liferay.portal.kernel.util.StringBundler;
019    import com.liferay.portal.kernel.util.Validator;
020    
021    import java.io.Serializable;
022    
023    /**
024     * @author Michael C. Han
025     */
026    public class DestinationConfiguration implements Serializable {
027    
028            public static final String DESTINATION_TYPE_PARALLEL = "parallel";
029    
030            public static final String DESTINATION_TYPE_SERIAL = "serial";
031    
032            public static final String DESTINATION_TYPE_SYNCHRONOUS = "synchronous";
033    
034            public static DestinationConfiguration
035                    createParallelDestinationConfiguration(String destinationName) {
036    
037                    return new DestinationConfiguration(
038                            DESTINATION_TYPE_PARALLEL, destinationName);
039            }
040    
041            public static DestinationConfiguration createSerialDestinationConfiguration(
042                    String destinationName) {
043    
044                    return new DestinationConfiguration(
045                            DESTINATION_TYPE_SERIAL, destinationName);
046            }
047    
048            public static DestinationConfiguration
049                    createSynchronousDestinationConfiguration(String destinationName) {
050    
051                    return new DestinationConfiguration(
052                            DESTINATION_TYPE_SYNCHRONOUS, destinationName);
053            }
054    
055            public DestinationConfiguration(
056                    String destinationType, String destinationName) {
057    
058                    _destinationType = destinationType;
059                    _destinationName = destinationName;
060            }
061    
062            @Override
063            public boolean equals(Object object) {
064                    if (this == object) {
065                            return true;
066                    }
067    
068                    if (!(object instanceof DestinationConfiguration)) {
069                            return false;
070                    }
071    
072                    DestinationConfiguration destinationConfiguration =
073                            (DestinationConfiguration)object;
074    
075                    if (Validator.equals(
076                                    _destinationName, destinationConfiguration._destinationName)) {
077    
078                            return true;
079                    }
080    
081                    return false;
082            }
083    
084            public String getDestinationName() {
085                    return _destinationName;
086            }
087    
088            public String getDestinationType() {
089                    return _destinationType;
090            }
091    
092            public int getMaximumQueueSize() {
093                    return _maximumQueueSize;
094            }
095    
096            public RejectedExecutionHandler getRejectedExecutionHandler() {
097                    return _rejectedExecutionHandler;
098            }
099    
100            public int getWorkersCoreSize() {
101                    return _workersCoreSize;
102            }
103    
104            public int getWorkersMaxSize() {
105                    return _workersMaxSize;
106            }
107    
108            @Override
109            public int hashCode() {
110                    return _destinationName.hashCode();
111            }
112    
113            public void setDestinationType(String destinationType) {
114                    _destinationType = destinationType;
115            }
116    
117            public void setMaximumQueueSize(int maximumQueueSize) {
118                    _maximumQueueSize = maximumQueueSize;
119            }
120    
121            public void setRejectedExecutionHandler(
122                    RejectedExecutionHandler rejectedExecutionHandler) {
123    
124                    _rejectedExecutionHandler = rejectedExecutionHandler;
125            }
126    
127            public void setWorkersCoreSize(int workersCoreSize) {
128                    _workersCoreSize = workersCoreSize;
129            }
130    
131            public void setWorkersMaxSize(int workersMaxSize) {
132                    _workersMaxSize = workersMaxSize;
133            }
134    
135            @Override
136            public String toString() {
137                    StringBundler sb = new StringBundler(13);
138    
139                    sb.append("{_destinationName=");
140                    sb.append(_destinationName);
141                    sb.append(", _destinationType=");
142                    sb.append(_destinationType);
143                    sb.append(", _maximumQueueSize=");
144                    sb.append(_maximumQueueSize);
145                    sb.append(", _rejectedExecutionHandler=");
146                    sb.append(_rejectedExecutionHandler);
147                    sb.append(", _workersCoreSize=");
148                    sb.append(_workersCoreSize);
149                    sb.append(", _workersMaxSize=");
150                    sb.append(_workersMaxSize);
151                    sb.append("}");
152    
153                    return sb.toString();
154            }
155    
156            private static final int _WORKERS_CORE_SIZE = 2;
157    
158            private static final int _WORKERS_MAX_SIZE = 5;
159    
160            private final String _destinationName;
161            private String _destinationType;
162            private int _maximumQueueSize = Integer.MAX_VALUE;
163            private RejectedExecutionHandler _rejectedExecutionHandler;
164            private int _workersCoreSize = _WORKERS_CORE_SIZE;
165            private int _workersMaxSize = _WORKERS_MAX_SIZE;
166    
167    }