changed to unmaintained
[aaf/authz.git] / cadi / client / src / main / java / org / onap / aaf / cadi / locator / SingleEndpointLocator.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21 package org.onap.aaf.cadi.locator;
22
23 import java.net.URI;
24 import java.net.URISyntaxException;
25 import java.util.Date;
26
27 import org.onap.aaf.cadi.LocatorException;
28 import org.onap.aaf.cadi.config.SecurityInfoC;
29
30 public class SingleEndpointLocator implements SizedLocator<URI> {
31     private final URI uri;
32     private final static Item item = new Item() {};
33     private Date noRetryUntil;
34
35     /**
36      * New constructor that works with the Config.loadLocator function
37      */
38     public SingleEndpointLocator(final SecurityInfoC<?> sec, final URI uri) throws LocatorException {
39         this.uri = uri;
40     }
41
42     public SingleEndpointLocator(final URI uri) {
43         this.uri = uri;
44     }
45
46     public SingleEndpointLocator(final String endpoint) throws LocatorException {
47         try {
48             this.uri = new URI(endpoint);
49         } catch (URISyntaxException e) {
50             throw new LocatorException(e);
51         }
52     }
53
54     @Override
55     public URI get(Item item) throws LocatorException {
56         return uri;
57     }
58
59     @Override
60     public boolean hasItems() {
61         if (noRetryUntil!=null) {
62             if (new Date().after(noRetryUntil)) {
63                 noRetryUntil = null;
64             } else {
65                 return false;
66             }
67         }
68         return true;
69     }
70
71     @Override
72     public void invalidate(Item item) throws LocatorException {
73         // one minute timeout, because there is no other item
74         noRetryUntil = new Date(System.currentTimeMillis()+60000);
75     }
76
77     @Override
78     public Item best() throws LocatorException {
79         return item;
80     }
81
82     @Override
83     public Item first() throws LocatorException {
84         return item;
85     }
86
87     @Override
88     public Item next(Item inItem) throws LocatorException {
89         // only one item
90         return null;
91     }
92
93     @Override
94     public boolean refresh() {
95         // Never refreshed
96         return true;
97     }
98
99     @Override
100     public int size() {
101         return 1;
102     }
103
104     @Override
105     public void destroy() {
106         // Nothing to do here
107     }
108 }