2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
21 package org.onap.aaf.auth.server;
22 import java.io.IOException;
23 import java.util.concurrent.ExecutorService;
24 import java.util.concurrent.Executors;
25 import java.util.concurrent.Future;
26 import java.util.concurrent.TimeUnit;
28 import org.onap.aaf.auth.org.OrganizationException;
29 import org.onap.aaf.auth.org.OrganizationFactory;
30 import org.onap.aaf.auth.rserv.RServlet;
31 import org.onap.aaf.cadi.Access;
32 import org.onap.aaf.cadi.Access.Level;
33 import org.onap.aaf.cadi.register.Registrant;
34 import org.onap.aaf.cadi.register.Registrar;
35 import org.onap.aaf.misc.env.Trans;
36 import org.onap.aaf.misc.rosetta.env.RosettaEnv;
38 public abstract class AbsServiceStarter<ENV extends RosettaEnv, TRANS extends Trans> implements ServiceStarter {
39 private Registrar<ENV> registrar;
40 private boolean do_register;
41 protected AbsService<ENV,TRANS> service;
44 public AbsServiceStarter(final AbsService<ENV,TRANS> service) {
45 this.service = service;
47 OrganizationFactory.init(service.env);
48 } catch (OrganizationException e) {
49 service.access.log(e, "Missing defined Organzation Plugins");
52 // do_register - this is used for specialty Debug Situations. Developer can create an Instance for a remote system
53 // for Debugging purposes without fear that real clients will start to call your debug instance
54 do_register = !"TRUE".equalsIgnoreCase(access().getProperty("aaf_locate_no_register",null));
55 _propertyAdjustment();
58 public abstract void _start(RServlet<TRANS> rserv) throws Exception;
59 public abstract void _propertyAdjustment();
65 public Access access() {
66 return service.access;
70 public final void start() throws Exception {
71 ExecutorService es = Executors.newSingleThreadExecutor();
72 Future<?> app = es.submit(this);
73 final AbsServiceStarter<?,?> absSS = this;
74 Runtime.getRuntime().addShutdownHook(new Thread() {
77 absSS.access().printf(Level.INIT, "Shutting down %s:%s\n",absSS.service.app_name, absSS.service.app_version);
82 if(System.getProperty("ECLIPSE", null)!=null) {
84 System.out.println("Service Started in Eclipse: ");
85 System.out.print(" Hit <enter> to end:");
89 } catch (IOException e) {
97 public final synchronized void register(final Registrant<ENV> ... registrants) {
99 if (registrar==null) {
100 registrar = new Registrar<ENV>(env(),false);
102 for (Registrant<ENV> r : registrants) {
103 registrar.register(r);
112 } catch (Exception e) {
118 public void shutdown() {
119 if (registrar!=null) {
120 registrar.close(env());