| 1 |
/* |
| 2 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 3 |
* or more contributor license agreements. See the NOTICE file |
| 4 |
* distributed with this work for additional information |
| 5 |
* regarding copyright ownership. The ASF licenses this file |
| 6 |
* to you under the Apache License, Version 2.0 (the |
| 7 |
* "License"); you may not use this file except in compliance |
| 8 |
* with the License. You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, |
| 13 |
* software distributed under the License is distributed on an |
| 14 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
* KIND, either express or implied. See the License for the |
| 16 |
* specific language governing permissions and limitations |
| 17 |
* under the License. |
| 18 |
* |
| 19 |
*/ |
| 20 |
package org.apache.directory.server; |
| 21 |
|
| 22 |
|
| 23 |
import org.apache.directory.server.core.api.InstanceLayout; |
| 24 |
import org.apache.felix.ipojo.annotations.Component; |
| 25 |
import org.apache.felix.ipojo.annotations.Instantiate; |
| 26 |
import org.apache.felix.ipojo.annotations.Invalidate; |
| 27 |
import org.apache.felix.ipojo.annotations.Property; |
| 28 |
import org.apache.felix.ipojo.annotations.Validate; |
| 29 |
import org.slf4j.Logger; |
| 30 |
import org.slf4j.LoggerFactory; |
| 31 |
|
| 32 |
|
| 33 |
/** |
| 34 |
* IPojo Component that represents live ApacheDS instance |
| 35 |
* |
| 36 |
* @author <a href="mailto:[email protected]">Apache Directory |
| 37 |
* Project</a> |
| 38 |
*/ |
| 39 |
@Component(name = "ApacheDSInstance") |
| 40 |
@Instantiate(name = "ApacheDSInstance-Default") |
| 41 |
public class ApacheDSInstance |
| 42 |
{ |
| 43 |
/** A logger for this class */ |
| 44 |
private final Logger LOG = LoggerFactory |
| 45 |
.getLogger( ApacheDSInstance.class ); |
| 46 |
|
| 47 |
/** Property for specifying instance directory. It is "default" by default */ |
| 48 |
@Property(name = "apacheds.instance.dir", value = "default") |
| 49 |
private String instanceDir; |
| 50 |
|
| 51 |
/* ApacheDSService reference */ |
| 52 |
private ApacheDsService service; |
| 53 |
|
| 54 |
|
| 55 |
/** |
| 56 |
* Will be called, when this component instance is validated, |
| 57 |
* Means all of its requirements are satisfied. |
| 58 |
* |
| 59 |
* |
| 60 |
*/ |
| 61 |
@Validate |
| 62 |
public void validated() |
| 63 |
{ |
| 64 |
service = new ApacheDsService(); |
| 65 |
|
| 66 |
// Creating instance layouts from the argument |
| 67 |
InstanceLayout instanceLayout = new InstanceLayout( instanceDir ); |
| 68 |
|
| 69 |
// Initializing the service |
| 70 |
try |
| 71 |
{ |
| 72 |
service.start( instanceLayout ); |
| 73 |
} |
| 74 |
catch ( Exception e ) |
| 75 |
{ |
| 76 |
e.printStackTrace(); |
| 77 |
LOG.error( "Failed to start the service.", e ); |
| 78 |
System.exit( 1 ); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
/** |
| 84 |
* Will be called when this component instance is invalidated, |
| 85 |
* means one of its requirements is lost. |
| 86 |
* |
| 87 |
*/ |
| 88 |
@Invalidate |
| 89 |
public void invalidated() |
| 90 |
{ |
| 91 |
//Stopping the service |
| 92 |
try |
| 93 |
{ |
| 94 |
service.stop(); |
| 95 |
} |
| 96 |
catch ( Exception e ) |
| 97 |
{ |
| 98 |
e.printStackTrace(); |
| 99 |
LOG.error( "Failed to stop the service.", e ); |
| 100 |
System.exit( 1 ); |
| 101 |
} |
| 102 |
} |
| 103 |
} |