View Javadoc

1   /*
2    * Copyright (c) 2015 Maxim Yunusov
3    *    Licensed under the Apache License, Version 2.0 (the "License");
4    *    you may not use this file except in compliance with the License.
5    *    You may obtain a copy of the License at
6    *
7    *        http://www.apache.org/licenses/LICENSE-2.0
8    *
9    *    Unless required by applicable law or agreed to in writing, software
10   *    distributed under the License is distributed on an "AS IS" BASIS,
11   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   *    See the License for the specific language governing permissions and
13   *    limitations under the License.
14   */
15  
16  package org.maxur.perfmodel.backend.service;
17  
18  import org.jvnet.hk2.annotations.Contract;
19  import org.slf4j.Logger;
20  import org.slf4j.LoggerFactory;
21  
22  import javax.annotation.PostConstruct;
23  import javax.inject.Inject;
24  
25  /**
26   * This interface represents Perfomance Model Standalone Application
27   *
28   * @author myunusov
29   * @version 1.0
30   * @since <pre>30.08.2015</pre>
31   */
32  @Contract
33  public abstract class Application {
34  
35      private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);
36  
37      @Inject
38      private WebServer webServer;
39  
40      @Inject
41      private Database db;
42  
43      @PostConstruct
44      public final void init() {
45          onInit();
46      }
47  
48      public final void start() {
49          webServer.start();
50          onStart();
51          LOGGER.info("Performance Model Calculator Server is started");
52      }
53  
54      public final void stop() {
55          webServer.stop();
56          db.stop();
57          onStop();
58          LOGGER.info("Performance Model Calculator Server is stopped");
59      }
60  
61      public String version() {
62          return this.getClass().getPackage().getImplementationVersion();
63      }
64  
65  
66      protected final  WebServer webServer() {
67          return webServer;
68      }
69  
70      /**
71       * Returns true if Application is applicable.
72       *
73       * @return true if Application is applicable
74       */
75      public abstract boolean isApplicable();
76  
77      /**
78       * Hook on Init
79       */
80      protected void onInit() {
81      }
82  
83      /**
84       * Hook on Start
85       */
86      protected void onStart() {
87      }
88  
89      /**
90       * Hook on Stop
91       */
92      protected void onStop() {
93      }
94  }