Project

General

Profile

Download (3.16 KB) Statistics
| Branch: | Tag: | Revision:
1
/*
2
 * ========================================================================
3
 * Based on Jetty 6 code from Mort Bay Consulting Pty. Ltd.
4
 * Modified for CDM Server by Andreas Kohlbecker. 2010-10-24
5
 * ========================================================================
6
 * Copyright 2004-2008 Mort Bay Consulting Pty. Ltd.
7
 * ------------------------------------------------------------------------
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at 
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 * ========================================================================
18
 */
19

    
20
package eu.etaxonomy.cdm.server.win32service;
21

    
22

    
23
import org.apache.log4j.Logger;
24
import org.eclipse.jetty.server.Server;
25
import org.tanukisoftware.wrapper.WrapperListener;
26
import org.tanukisoftware.wrapper.WrapperManager;
27
/**
28
 * @author a.kohlbecker
29
 * @date 26.10.2010
30
 *
31
 */
32
public class CDMServerWrapperListener implements WrapperListener
33
{
34
    private static Server __server = null;
35
    
36
    public static final Logger logger = Logger.getLogger(CDMServerWrapperListener.class);
37

    
38
    public CDMServerWrapperListener()
39
    {
40
    }
41

    
42
    public void controlEvent(int event)
43
    {
44
        if (!WrapperManager.isControlledByNativeWrapper())
45
        {
46
            if ((event == WrapperManager.WRAPPER_CTRL_C_EVENT) || (event == WrapperManager.WRAPPER_CTRL_CLOSE_EVENT) || (event == WrapperManager.WRAPPER_CTRL_SHUTDOWN_EVENT))
47
            {
48
                WrapperManager.stop(0);
49
            }
50
        }
51

    
52
    }
53

    
54
    public Integer start(String[] args)
55
    {
56
        for(int i=0; i<args.length; i++)
57
        {
58
        	logger.info("ARG[" + i + "] = " + args[i]);
59
        }
60
        try {
61
			eu.etaxonomy.cdm.server.Bootloader.main(args);
62
		} catch (Exception e) {
63
			e.printStackTrace();
64
		}
65
        return null;
66
    }
67

    
68
    public int stop(int code)
69
    {
70
        try
71
        {
72
        	logger.info("Stopping CDM Server!!!");
73
            __server.stop();
74
            logger.info("CDM Server Stopped!!!");
75
            return code;
76
        }
77
        catch (Exception e)
78
        {
79
        	logger.error("Stop Server Error");
80
            e.printStackTrace();
81
            return -1;
82
        }
83

    
84
    }
85

    
86
    /**
87
     * @param server
88
     */
89
    public static void setServer(Server server)
90
    {
91
        __server = server;
92
    }
93

    
94
    /**
95
     * @return
96
     */
97
    public static Server getServer()
98
    {
99
        return __server;
100
    }
101

    
102
    public static void main(String[] args)
103
    {
104
        String newStrArgs[] = new String[args.length + 1];
105
        newStrArgs[0] = System.getProperty("jetty.home") + "etc/jetty-win32-service.xml";
106
        for(int i=0; i<args.length; i++)
107
        {
108
            newStrArgs[i+1] = args[i];
109
        }
110
        WrapperManager.start(new CDMServerWrapperListener(), newStrArgs);
111
    }
112

    
113
}
(1-1/2)