2 * Copyright 2016 Huawei Technologies Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient;
19 import java.util.HashMap;
23 * Options for Rest communication.<br/>
28 * @version 28-May-2016
30 public class RestfulOptions {
32 public static final String REST_OPTIONS_NAME_TIMEOUT = "timeout";
34 public static final int REST_OPTIONS_TIMEOUT_MAXTIMEOUT = 1800000;
36 private final Map<String, Object> optionsMap = new HashMap<>();
44 public int getPort() {
45 final Object obj = this.getOption(RestfulClientConst.PORT_KEY_NAME);
49 return ((Integer)obj).intValue();
55 * @param port port to set.
59 public boolean setPort(final int port) {
60 this.setOption(RestfulClientConst.PORT_KEY_NAME, port);
70 public String getHost() {
71 final Object obj = this.getOption(RestfulClientConst.HOST_KEY_NAME);
81 * @param host host to set.
85 public boolean setHost(final String host) {
86 this.setOption(RestfulClientConst.HOST_KEY_NAME, host);
91 * Set rest time-out.<br/>
93 * @param timeout time-out to set in seconds.
97 public boolean setRestTimeout(final int timeout) {
98 if(0 < timeout && REST_OPTIONS_TIMEOUT_MAXTIMEOUT >= timeout) {
99 this.setOption(REST_OPTIONS_NAME_TIMEOUT, timeout);
108 * @return time-out in seconds.
111 public int getRestTimeout() {
112 final Object obj = this.getOption(REST_OPTIONS_NAME_TIMEOUT);
116 return ((Integer)obj).intValue();
120 * Get specified option.<br/>
122 * @param optionName option name.
126 public Object getOption(final String optionName) {
127 return optionsMap.get(optionName);
131 * Get option value as integer.<br/>
133 * @param optionName option name.
134 * @return option value as int.
137 public int getIntOption(final String optionName) {
138 final Object obj = this.getOption(optionName);
142 return ((Integer)obj).intValue();
146 * Get option value as string.<br/>
148 * @param optionName option name.
149 * @return option value as string.
152 public String getStringOption(final String optionName) {
153 final Object obj = this.getOption(optionName);
163 * @param option option name.
164 * @param optionsValue option value.
168 public Object setOption(final String option, final Object optionsValue) {
169 return optionsMap.put(option, optionsValue);