Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
joram
joram
Commits
a981536e
Commit
a981536e
authored
Apr 13, 2012
by
Nicolas Tachker
Browse files
Start the A3 server with configuration admin file.
parent
2d37c1a7
Changes
3
Hide whitespace changes
Inline
Side-by-side
joram/a3/osgi/src/main/java/fr/dyade/aaa/agent/osgi/A3ManagedService.java
0 → 100644
View file @
a981536e
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2012 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package
fr.dyade.aaa.agent.services
;
import
java.util.Dictionary
;
import
java.util.Enumeration
;
import
java.util.Properties
;
import
org.objectweb.util.monolog.api.BasicLevel
;
import
org.objectweb.util.monolog.api.Logger
;
import
org.osgi.framework.BundleActivator
;
import
org.osgi.framework.BundleContext
;
import
org.osgi.framework.Constants
;
import
org.osgi.framework.ServiceRegistration
;
import
org.osgi.service.cm.ConfigurationException
;
import
org.osgi.service.cm.ManagedService
;
import
org.ow2.util.substitution.engine.DefaultSubstitutionEngine
;
import
org.ow2.util.substitution.resolver.ChainedResolver
;
import
org.ow2.util.substitution.resolver.PropertiesResolver
;
import
org.ow2.util.substitution.resolver.RecursiveResolver
;
import
fr.dyade.aaa.agent.AgentServer
;
import
fr.dyade.aaa.agent.ServerDesc
;
import
fr.dyade.aaa.common.Debug
;
/**
* Start the a3 server with a ConfigAdmin file.
* <p>The default values
* <ul>
* <li> sid (server id) : 0
* <li> storage : s0
* <li> pathToConf : "."
* </ul>
*
* <p><hr>
* The reserved words for properties:
* <ul>
* <li> sid
* <li> cid
* <li> storage
* <li> pathToConf
* </ul>
*
* <p><hr>
* A simple example:
* <p><blockquote><pre>
* <configadmin>
* <configuration pid="fr.dyade.aaa.agent.services.A3ManagedService">
* <property name="sid">0</property>
* <property name="storage">your_path/s0</property>
* <property name="pathToConf">your_path/conf</property>
* <!-- properties -->
* <property name="Transaction">fr.dyade.aaa.util.NTransaction</property>
* <property name="NTNoLockFile">true</property>
* </configuration>
* </configadmin>
* </pre></blockquote>
*
*/
public
class
A3ManagedService
implements
ManagedService
,
BundleActivator
{
public
static
final
Logger
logmon
=
Debug
.
getLogger
(
A3ManagedService
.
class
.
getName
());
// The reserved words.
/** the server id */
public
static
final
String
SID
=
"sid"
;
/** the cluster id */
public
static
final
String
CID
=
"cid"
;
/** persistence directory */
public
static
final
String
STORAGE
=
"storage"
;
/** the path to the configuration (a3servers.xml, ...) */
public
static
final
String
PATH_TO_CONF
=
"pathToConf"
;
private
short
sid
=
0
;
private
short
cid
=
AgentServer
.
NULL_ID
;
private
String
path
=
"s0"
;
private
BundleContext
bundleContext
;
private
ServiceRegistration
registration
;
/* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public
void
start
(
final
BundleContext
bundleContext
)
throws
Exception
{
if
(
logmon
.
isLoggable
(
BasicLevel
.
DEBUG
))
logmon
.
log
(
BasicLevel
.
DEBUG
,
"start("
+
bundleContext
+
')'
);
this
.
bundleContext
=
bundleContext
;
Properties
props
=
new
Properties
();
props
.
setProperty
(
Constants
.
SERVICE_PID
,
A3ManagedService
.
class
.
getName
());
registration
=
this
.
bundleContext
.
registerService
(
ManagedService
.
class
.
getName
(),
this
,
props
);
}
/* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public
void
stop
(
BundleContext
context
)
throws
Exception
{
doStop
();
registration
.
unregister
();
}
protected
void
doStart
()
throws
Exception
{
if
(
logmon
.
isLoggable
(
BasicLevel
.
DEBUG
))
logmon
.
log
(
BasicLevel
.
DEBUG
,
"A3ManagedService.doStart()"
);
try
{
AgentServer
.
init
(
sid
,
path
,
null
,
cid
);
}
catch
(
Exception
exc
)
{
logmon
.
log
(
BasicLevel
.
ERROR
,
AgentServer
.
getName
()
+
" initialization failed"
,
exc
);
throw
exc
;
}
try
{
String
errStr
=
AgentServer
.
start
();
if
(
errStr
==
null
)
{
if
(
logmon
.
isLoggable
(
BasicLevel
.
INFO
))
logmon
.
log
(
BasicLevel
.
INFO
,
AgentServer
.
getName
()
+
" started: "
+
AgentServer
.
OKSTRING
);
}
else
{
if
(
logmon
.
isLoggable
(
BasicLevel
.
INFO
))
{
logmon
.
log
(
BasicLevel
.
INFO
,
AgentServer
.
getName
()
+
" started: "
+
AgentServer
.
ERRORSTRING
+
"\n"
+
errStr
+
"\n"
+
AgentServer
.
ENDSTRING
);
}
}
}
catch
(
Exception
exc
)
{
logmon
.
log
(
BasicLevel
.
ERROR
,
AgentServer
.
getName
()
+
" failed"
,
exc
);
throw
exc
;
}
// Register ServerDesc
ServerDesc
serverDesc
=
AgentServer
.
getServerDesc
(
sid
);
Properties
props
=
new
Properties
();
props
.
setProperty
(
"sid"
,
""
+
sid
);
props
.
setProperty
(
"name"
,
serverDesc
.
getServerName
());
props
.
setProperty
(
"host"
,
serverDesc
.
getHostname
());
props
.
setProperty
(
"port"
,
""
+
serverDesc
.
getPort
());
bundleContext
.
registerService
(
ServerDesc
.
class
.
getName
(),
serverDesc
,
props
);
if
(
logmon
.
isLoggable
(
BasicLevel
.
DEBUG
))
logmon
.
log
(
BasicLevel
.
DEBUG
,
"A3managedService ServerDesc register: "
+
serverDesc
);
}
protected
void
doStop
()
{
if
(
logmon
.
isLoggable
(
BasicLevel
.
DEBUG
))
logmon
.
log
(
BasicLevel
.
DEBUG
,
"A3ManagedService.doStop(): AgentServer status = "
+
AgentServer
.
getStatusInfo
());
if
(
AgentServer
.
getStatus
()
==
AgentServer
.
Status
.
STARTING
||
AgentServer
.
getStatus
()
==
AgentServer
.
Status
.
STARTED
)
{
AgentServer
.
stop
();
AgentServer
.
reset
();
}
}
//************ ManagedService ************
public
String
getName
()
{
return
"A3ManagedService"
;
}
/* (non-Javadoc)
* @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
*/
public
void
updated
(
Dictionary
properties
)
throws
ConfigurationException
{
if
(
logmon
.
isLoggable
(
BasicLevel
.
DEBUG
))
logmon
.
log
(
BasicLevel
.
DEBUG
,
"updated("
+
properties
+
')'
);
if
(
properties
==
null
)
{
doStop
();
return
;
}
String
sidStr
=
(
String
)
properties
.
get
(
SID
);
if
(
sidStr
!=
null
&&
sidStr
.
length
()
>
0
)
{
sid
=
new
Short
(
sidStr
).
shortValue
();
}
String
cidStr
=
(
String
)
properties
.
get
(
CID
);
if
(
cidStr
!=
null
&&
cidStr
.
length
()
>
0
)
{
cid
=
new
Short
(
cidStr
).
shortValue
();
}
DefaultSubstitutionEngine
engine
=
new
DefaultSubstitutionEngine
();
ChainedResolver
resolver
=
new
ChainedResolver
();
resolver
.
getResolvers
().
add
(
new
PropertiesResolver
(
System
.
getProperties
()));
engine
.
setResolver
(
new
RecursiveResolver
(
engine
,
resolver
));
String
storage
=
(
String
)
properties
.
get
(
STORAGE
);
if
(
storage
!=
null
&&
storage
.
length
()
>
0
)
{
path
=
engine
.
substitute
(
storage
);
}
String
pathToConf
=
(
String
)
properties
.
get
(
PATH_TO_CONF
);
if
(
pathToConf
!=
null
&&
pathToConf
.
length
()
>
0
)
{
System
.
setProperty
(
AgentServer
.
CFG_DIR_PROPERTY
,
engine
.
substitute
(
pathToConf
));
}
// set System properties if needed
Enumeration
en
=
properties
.
keys
();
while
(
en
.
hasMoreElements
())
{
String
key
=
(
String
)
en
.
nextElement
();
if
(
SID
.
equals
(
key
)
||
CID
.
equals
(
key
)
||
STORAGE
.
equals
(
key
)
||
PATH_TO_CONF
.
equals
(
key
))
{
// reserved word.
continue
;
}
else
{
String
value
=
(
String
)
properties
.
get
(
key
);
if
(
value
!=
null
)
System
.
setProperty
(
key
,
value
);
}
}
// start the a3 server
try
{
doStart
();
}
catch
(
Exception
e
)
{
if
(
logmon
.
isLoggable
(
BasicLevel
.
ERROR
))
logmon
.
log
(
BasicLevel
.
ERROR
,
"updated:: doStart EXCEPTION"
,
e
);
throw
new
ConfigurationException
(
null
,
e
.
getMessage
());
}
}
}
\ No newline at end of file
joram/a3/services/pom.xml
0 → 100644
View file @
a981536e
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
a3-services
</artifactId>
<packaging>
bundle
</packaging>
<name>
JORAM :: a3 :: services
</name>
<description>
Builds the Joram a3 services project.
</description>
<parent>
<groupId>
org.ow2.joram
</groupId>
<artifactId>
a3
</artifactId>
<version>
5.8.0-SNAPSHOT
</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>
org.apache.felix
</groupId>
<artifactId>
maven-bundle-plugin
</artifactId>
<version>
${maven.bundle.plugin.version}
</version>
<extensions>
true
</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>
${project.artifactId}
</Bundle-SymbolicName>
<Bundle-Activator>
fr.dyade.aaa.agent.services.A3ManagedService
</Bundle-Activator>
<Export-Package>
fr.dyade.aaa.agent.services
</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>
org.ow2.joram
</groupId>
<artifactId>
a3-rt
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.ow2.bundles
</groupId>
<artifactId>
ow2-util-substitution
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
joram/a3/services/src/main/resources/sampleA3ConfigAdmin.xml
0 → 100644
View file @
a981536e
<?xml version="1.0" encoding="UTF-8"?>
<!--
JORAM: Java(TM) Open Reliable Asynchronous Messaging
Copyright (C) 2012 ScalAgent Distributed Technologies
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
-->
<configadmin
xmlns=
"http://jonas.ow2.org/ns/configadmin/1.0"
>
<!-- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jonas.ow2.org/ns/configadmin/1.0
configadmin-1.0.xsd" -->
<configuration
pid=
"fr.dyade.aaa.agent.services.A3ManagedService"
>
<!-- requires properties -->
<!-- the server id -->
<property
name=
"sid"
>
0
</property>
<!-- persistence directory -->
<property
name=
"storage"
>
${jonas.base}/work/s0
</property>
<!-- path to the configuration: a3servers.xml -->
<property
name=
"pathToConf"
>
${jonas.base}/conf
</property>
<!-- overall properties -->
<property
name=
"Transaction"
>
fr.dyade.aaa.util.NTransaction
</property>
<property
name=
"NTNoLockFile"
>
true
</property>
</configuration>
</configadmin>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment