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    
020    import java.io.Serializable;
021    
022    import java.util.Objects;
023    
024    /**
025     * @author Michael C. Han
026     */
027    public class DestinationConfiguration implements Serializable {
028    
029            public static final String DESTINATION_TYPE_PARALLEL = "parallel";
030    
031            public static final String DESTINATION_TYPE_SERIAL = "serial";
032    
033            public static final String DESTINATION_TYPE_SYNCHRONOUS = "synchronous";
034    
035            public static DestinationConfiguration
036                    createParallelDestinationConfiguration(String destinationName) {
037    
038                    return new DestinationConfiguration(
039                            DESTINATION_TYPE_PARALLEL, destinationName);
040            }
041    
042            public static DestinationConfiguration createSerialDestinationConfiguration(
043                    String destinationName) {
044    
045                    return new DestinationConfiguration(
046                            DESTINATION_TYPE_SERIAL, destinationName);
047            }
048    
049            public static DestinationConfiguration
050                    createSynchronousDestinationConfiguration(String destinationName) {
051    
052                    return new DestinationConfiguration(
053                            DESTINATION_TYPE_SYNCHRONOUS, destinationName);
054            }
055    
056            public DestinationConfiguration(
057                    String destinationType, String destinationName) {
058    
059                    _destinationType = destinationType;
060                    _destinationName = destinationName;
061            }
062    
063            @Override
064            public boolean equals(Object object) {
065                    if (this == object) {
066                            return true;
067                    }
068    
069                    if (!(object instanceof DestinationConfiguration)) {
070                            return false;
071                    }
072    
073                    DestinationConfiguration destinationConfiguration =
074                            (DestinationConfiguration)object;
075    
076                    if (Objects.equals(
077                                    _destinationName, destinationConfiguration._destinationName)) {
078    
079                            return true;
080                    }
081    
082                    return false;
083            }
084    
085            public String getDestinationName() {
086                    return _destinationName;
087            }
088    
089            public String getDestinationType() {
090                    return _destinationType;
091            }
092    
093            public int getMaximumQueueSize() {
094                    return _maximumQueueSize;
095            }
096    
097            public RejectedExecutionHandler getRejectedExecutionHandler() {
098                    return _rejectedExecutionHandler;
099            }
100    
101            public int getWorkersCoreSize() {
102                    return _workersCoreSize;
103            }
104    
105            public int getWorkersMaxSize() {
106                    return _workersMaxSize;
107            }
108    
109            @Override
110            public int hashCode() {
111                    return _destinationName.hashCode();
112            }
113    
114            public void setDestinationType(String destinationType) {
115                    _destinationType = destinationType;
116            }
117    
118            public void setMaximumQueueSize(int maximumQueueSize) {
119                    _maximumQueueSize = maximumQueueSize;
120            }
121    
122            public void setRejectedExecutionHandler(
123                    RejectedExecutionHandler rejectedExecutionHandler) {
124    
125                    _rejectedExecutionHandler = rejectedExecutionHandler;
126            }
127    
128            public void setWorkersCoreSize(int workersCoreSize) {
129                    _workersCoreSize = workersCoreSize;
130            }
131    
132            public void setWorkersMaxSize(int workersMaxSize) {
133                    _workersMaxSize = workersMaxSize;
134            }
135    
136            @Override
137            public String toString() {
138                    StringBundler sb = new StringBundler(13);
139    
140                    sb.append("{_destinationName=");
141                    sb.append(_destinationName);
142                    sb.append(", _destinationType=");
143                    sb.append(_destinationType);
144                    sb.append(", _maximumQueueSize=");
145                    sb.append(_maximumQueueSize);
146                    sb.append(", _rejectedExecutionHandler=");
147                    sb.append(_rejectedExecutionHandler);
148                    sb.append(", _workersCoreSize=");
149                    sb.append(_workersCoreSize);
150                    sb.append(", _workersMaxSize=");
151                    sb.append(_workersMaxSize);
152                    sb.append("}");
153    
154                    return sb.toString();
155            }
156    
157            private static final int _WORKERS_CORE_SIZE = 2;
158    
159            private static final int _WORKERS_MAX_SIZE = 5;
160    
161            private final String _destinationName;
162            private String _destinationType;
163            private int _maximumQueueSize = Integer.MAX_VALUE;
164            private RejectedExecutionHandler _rejectedExecutionHandler;
165            private int _workersCoreSize = _WORKERS_CORE_SIZE;
166            private int _workersMaxSize = _WORKERS_MAX_SIZE;
167    
168    }