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.fabric.netty.client;
016    
017    import com.liferay.portal.fabric.netty.fileserver.CompressionLevel;
018    import com.liferay.portal.kernel.util.GetterUtil;
019    import com.liferay.portal.kernel.util.PropsKeys;
020    import com.liferay.portal.kernel.util.StringBundler;
021    import com.liferay.portal.kernel.util.SystemProperties;
022    
023    import java.io.File;
024    import java.io.Serializable;
025    
026    import java.nio.file.Path;
027    
028    import java.util.Properties;
029    
030    /**
031     * @author Shuyang Zhou
032     */
033    public class NettyFabricClientConfig implements Serializable {
034    
035            public NettyFabricClientConfig(String id, Properties properties) {
036                    _id = id;
037                    _properties = properties;
038    
039                    _repositoryFolder = new File(
040                            SystemProperties.get(SystemProperties.TMP_DIR),
041                            "NettyFabricClient-repository-" + id);
042            }
043    
044            public int getEventLoopGroupThreadCount() {
045                    return GetterUtil.getInteger(
046                            _properties.getProperty(
047                                    PropsKeys.PORTAL_FABRIC_CLIENT_EVENT_LOOP_GROUP_THREAD_COUNT),
048                            1);
049            }
050    
051            public int getExecutionGroupThreadCount() {
052                    return GetterUtil.getInteger(
053                            _properties.getProperty(
054                                    PropsKeys.PORTAL_FABRIC_CLIENT_EXECUTION_GROUP_THREAD_COUNT),
055                            1);
056            }
057    
058            public int getExecutionTimeout() {
059                    return GetterUtil.getInteger(
060                            _properties.getProperty(
061                                    PropsKeys.PORTAL_FABRIC_CLIENT_EXECUTION_TIMEOUT),
062                            600000);
063            }
064    
065            public CompressionLevel getFileServerFolderCompressionLevel() {
066                    return CompressionLevel.getCompressionLevel(
067                            GetterUtil.getInteger(
068                                    _properties.getProperty(
069                                            PropsKeys.PORTAL_FABRIC_CLIENT_FILE_SERVER_FOLDER_COMPRESSION_LEVEL),
070                                    1));
071            }
072    
073            public int getFileServerGroupThreadCount() {
074                    return GetterUtil.getInteger(
075                            _properties.getProperty(
076                                    PropsKeys.PORTAL_FABRIC_CLIENT_FILE_SERVER_GROUP_THREAD_COUNT),
077                            1);
078            }
079    
080            public String getNettyFabricServerHost() {
081                    return GetterUtil.getString(
082                            _properties.getProperty(PropsKeys.PORTAL_FABRIC_SERVER_HOST),
083                            "localhost");
084            }
085    
086            public int getNettyFabricServerPort() {
087                    return GetterUtil.getInteger(
088                            _properties.getProperty(PropsKeys.PORTAL_FABRIC_SERVER_PORT), 8923);
089            }
090    
091            public int getReconnectCount() {
092                    return GetterUtil.getInteger(
093                            _properties.getProperty(
094                                    PropsKeys.PORTAL_FABRIC_CLIENT_RECONNECT_COUNT),
095                            3);
096            }
097    
098            public long getReconnectInterval() {
099                    return GetterUtil.getInteger(
100                            _properties.getProperty(
101                                    PropsKeys.PORTAL_FABRIC_CLIENT_RECONNECT_INTERVAL),
102                            10000);
103            }
104    
105            public long getRepositoryGetFileTimeout() {
106                    return GetterUtil.getLong(
107                            _properties.getProperty(
108                                    PropsKeys.PORTAL_FABRIC_CLIENT_REPOSITORY_GET_FILE_TIMEOUT),
109                            600000);
110            }
111    
112            public Path getRepositoryPath() {
113                    return _repositoryFolder.toPath();
114            }
115    
116            public int getRPCGroupThreadCount() {
117                    return GetterUtil.getInteger(
118                            _properties.getProperty(
119                                    PropsKeys.PORTAL_FABRIC_CLIENT_RPC_GROUP_THREAD_COUNT),
120                            1);
121            }
122    
123            @Override
124            public String toString() {
125                    StringBundler sb = new StringBundler(27);
126    
127                    sb.append("{eventLoopGroupThreadCount=");
128                    sb.append(getEventLoopGroupThreadCount());
129                    sb.append(", executionGroupThreadCount=");
130                    sb.append(getExecutionGroupThreadCount());
131                    sb.append(", executionTimeout=");
132                    sb.append(getExecutionTimeout());
133                    sb.append(", fileServerFolderCompressionLevel=");
134                    sb.append(getFileServerFolderCompressionLevel());
135                    sb.append(", fileServerGroupThreadCount=");
136                    sb.append(getFileServerGroupThreadCount());
137                    sb.append(", id=");
138                    sb.append(_id);
139                    sb.append(", nettyFabricServetHost=");
140                    sb.append(getNettyFabricServerHost());
141                    sb.append(", nettyFabricServerPort=");
142                    sb.append(getNettyFabricServerPort());
143                    sb.append(", reconnectCount=");
144                    sb.append(getReconnectCount());
145                    sb.append(", reconnectInterval=");
146                    sb.append(getReconnectInterval());
147                    sb.append(", repositoryGetFileTimeout=");
148                    sb.append(getRepositoryGetFileTimeout());
149                    sb.append(", repositoryPath=");
150                    sb.append(getRepositoryPath());
151                    sb.append(", rpcGroupThreadCount=");
152                    sb.append(getRPCGroupThreadCount());
153                    sb.append("}");
154    
155                    return sb.toString();
156            }
157    
158            private static final long serialVersionUID = 1L;
159    
160            private final String _id;
161            private final Properties _properties;
162            private final File _repositoryFolder;
163    
164    }