blob: 3f0b08d21446c0e1dde7ccb10bdf473014d94592 [file] [log] [blame]
Shuyi Chend7955ce2013-05-22 14:51:55 -07001/*
2 * Copyright 2009 Mike Cumings
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
17package com.kenai.jbosh;
18
19import java.util.concurrent.TimeUnit;
20
21/**
22 * Data type representing the getValue of the {@code polling} attribute of the
23 * {@code bosh} element.
24 */
25final class AttrPolling extends AbstractIntegerAttr {
26
27 /**
28 * Creates a new attribute object.
29 *
30 * @param val attribute getValue
31 * @throws BOSHException on parse or validation failure
32 */
33 private AttrPolling(final String str) throws BOSHException {
34 super(str);
35 checkMinValue(0);
36 }
37
38 /**
39 * Creates a new attribute instance from the provided String.
40 *
41 * @param str string representation of the attribute
42 * @return instance of the attribute for the specified string, or
43 * {@code null} if input string is {@code null}
44 * @throws BOSHException on parse or validation failure
45 */
46 static AttrPolling createFromString(final String str)
47 throws BOSHException {
48 if (str == null) {
49 return null;
50 } else {
51 return new AttrPolling(str);
52 }
53 }
54
55 /**
56 * Get the polling interval in milliseconds.
57 *
58 * @return polling interval in milliseconds
59 */
60 public int getInMilliseconds() {
61 return (int) TimeUnit.MILLISECONDS.convert(
62 intValue(), TimeUnit.SECONDS);
63 }
64
65}