Skip to content
GitLab
Menu
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
2a5a4aa5
Commit
2a5a4aa5
authored
Jun 22, 2010
by
Nicolas Tachker
Browse files
maven migration.
parent
5435985a
Changes
155
Expand all
Hide whitespace changes
Inline
Side-by-side
joram/a3/common/pom.xml
0 → 100644
View file @
2a5a4aa5
<?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>
<groupId>
org.objectweb.joram
</groupId>
<artifactId>
a3-common
</artifactId>
<packaging>
bundle
</packaging>
<name>
JORAM :: a3 :: common
</name>
<description>
Builds the Joram a3 common project.
</description>
<parent>
<groupId>
org.objectweb.joram
</groupId>
<artifactId>
a3
</artifactId>
<version>
5.3.2.53-SNAPSHOT
</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>
org.apache.felix
</groupId>
<artifactId>
maven-bundle-plugin
</artifactId>
<extensions>
true
</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>
${pom.artifactId}
</Bundle-SymbolicName>
<DynamicImport-Package>
*
</DynamicImport-Package>
<Bundle-Activator>
fr.dyade.aaa.common.osgi.Activator
</Bundle-Activator>
<Export-Package>
com.scalagent.jmx,
fr.dyade.aaa.common,
fr.dyade.aaa.common.monitoring,
fr.dyade.aaa.common.net,
fr.dyade.aaa.common.stream,
fr.dyade.aaa.common.soap,
fr.dyade.aaa.util.management
</Export-Package>
<Import-Package>
javax.management;resolution:=optional,
org.objectweb.util.monolog,
org.objectweb.util.monolog.api,
org.osgi.framework
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>
org.ow2.jonas.osgi
</groupId>
<artifactId>
monolog
</artifactId>
</dependency>
<dependency>
<groupId>
org.osgi
</groupId>
<artifactId>
org.osgi
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
joram/a3/common/src/main/java/com/scalagent/jmx/JMXServer.java
0 → 100644
View file @
2a5a4aa5
/*
* Copyright (C) 2001 - 2009 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
com.scalagent.jmx
;
import
java.lang.reflect.Method
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Hashtable
;
import
java.util.Map
;
import
java.util.Set
;
import
javax.management.InstanceAlreadyExistsException
;
import
javax.management.InstanceNotFoundException
;
import
javax.management.MBeanAttributeInfo
;
import
javax.management.MBeanRegistrationException
;
import
javax.management.MBeanServer
;
import
javax.management.MBeanServerFactory
;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.ObjectName
;
import
javax.management.RuntimeOperationsException
;
import
org.osgi.framework.ServiceRegistration
;
import
fr.dyade.aaa.common.osgi.Activator
;
import
fr.dyade.aaa.util.management.MXServer
;
import
fr.dyade.aaa.util.management.MXWrapper
;
/**
*
*/
public
class
JMXServer
implements
MXServer
{
private
MBeanServer
mxserver
=
null
;
private
Map
registeredServices
=
new
HashMap
();
public
static
boolean
registerAsService
=
false
;
public
JMXServer
(
MBeanServer
mxserver
)
{
this
.
mxserver
=
mxserver
;
MXWrapper
.
setMXServer
(
this
);
}
public
JMXServer
()
{
try
{
// Try to get the default platform MBeanServer (since JDK 1.5)
Class
clazz
=
Class
.
forName
(
"java.lang.management.ManagementFactory"
);
Method
method
=
clazz
.
getMethod
(
"getPlatformMBeanServer"
,
(
Class
[])
null
);
mxserver
=
(
MBeanServer
)
method
.
invoke
(
null
,
(
Object
[])
null
);
}
catch
(
Exception
exc
)
{
// Prior JDK1.5 (with JMXRI implementation).
mxserver
=
MBeanServerFactory
.
createMBeanServer
(
"AgentServer"
);
}
MXWrapper
.
setMXServer
(
this
);
}
private
void
registerOSGi
(
Object
obj
,
ObjectName
objName
)
{
if
(!
registerAsService
)
{
return
;
}
Hashtable
registrationProperties
=
objName
.
getKeyPropertyList
();
registrationProperties
.
put
(
"domain"
,
objName
.
getDomain
());
if
(
registeredServices
.
containsKey
(
objName
))
{
ServiceRegistration
registration
=
(
ServiceRegistration
)
registeredServices
.
get
(
objName
);
registration
.
setProperties
(
registrationProperties
);
return
;
}
else
{
Set
serviceNames
=
new
HashSet
();
computeOSGiServiceNames
(
obj
.
getClass
(),
obj
,
serviceNames
);
ServiceRegistration
registration
=
Activator
.
context
.
registerService
((
String
[])
serviceNames
.
toArray
(
new
String
[
serviceNames
.
size
()]),
obj
,
registrationProperties
);
registeredServices
.
put
(
objName
,
registration
);
}
}
private
void
computeOSGiServiceNames
(
Class
beanClass
,
Object
bean
,
Set
registered
)
{
if
(
beanClass
==
null
)
{
return
;
}
Class
[]
interfaces
=
beanClass
.
getInterfaces
();
for
(
int
i
=
0
;
i
<
interfaces
.
length
;
i
++)
{
if
(
interfaces
[
i
].
getName
().
endsWith
(
"MBean"
)
&&
!
registered
.
contains
(
interfaces
[
i
].
getName
()))
{
registered
.
add
(
interfaces
[
i
].
getName
());
computeOSGiServiceNames
(
interfaces
[
i
],
bean
,
registered
);
}
}
computeOSGiServiceNames
(
beanClass
.
getSuperclass
(),
bean
,
registered
);
}
public
String
registerMBean
(
Object
bean
,
String
fullName
)
throws
Exception
{
if
(
mxserver
==
null
)
return
null
;
// Debug.getLogger("toto").log(BasicLevel.ERROR, "Register MBean: " + fullName);
try
{
ObjectName
objName
=
ObjectName
.
getInstance
(
fullName
);
mxserver
.
registerMBean
(
bean
,
objName
);
registerOSGi
(
bean
,
objName
);
}
catch
(
InstanceAlreadyExistsException
exc
)
{
// The MBean is already under the control of the MBean server.
throw
exc
;
}
catch
(
MBeanRegistrationException
exc
)
{
// The preRegister (MBeanRegistration interface) method of the MBean
// has thrown an exception. The MBean will not be registered.
throw
exc
;
}
catch
(
NotCompliantMBeanException
exc
)
{
// This object is not a JMX compliant MBean
throw
exc
;
}
catch
(
RuntimeOperationsException
exc
)
{
// Wraps a java.lang.IllegalArgumentException
throw
exc
;
}
return
fullName
;
}
public
void
unregisterMBean
(
String
fullName
)
throws
Exception
{
if
(
mxserver
==
null
)
return
;
try
{
ObjectName
objName
=
ObjectName
.
getInstance
(
fullName
);
mxserver
.
unregisterMBean
(
objName
);
if
(
registerAsService
)
{
ServiceRegistration
registration
=
(
ServiceRegistration
)
registeredServices
.
remove
(
objName
);
if
(
registration
!=
null
)
{
registration
.
unregister
();
}
}
}
catch
(
InstanceNotFoundException
exc
)
{
// The MBean is not registered in the MBean server.
throw
exc
;
}
catch
(
MBeanRegistrationException
exc
)
{
// The preDeregister (MBeanRegistration interface) method of the MBean
// has thrown an exception.
throw
exc
;
}
catch
(
RuntimeOperationsException
exc
)
{
// Wraps a java.lang.IllegalArgumentException
throw
exc
;
}
}
public
Object
getAttribute
(
ObjectName
objectName
,
String
attribute
)
throws
Exception
{
if
(
mxserver
==
null
)
{
return
null
;
}
return
mxserver
.
getAttribute
(
objectName
,
attribute
);
}
public
MBeanAttributeInfo
[]
getAttributes
(
ObjectName
objectName
)
throws
Exception
{
if
(
mxserver
==
null
)
{
return
null
;
}
return
mxserver
.
getMBeanInfo
(
objectName
).
getAttributes
();
}
public
Set
queryNames
(
ObjectName
objectName
)
{
if
(
mxserver
==
null
)
{
return
null
;
}
return
mxserver
.
queryNames
(
objectName
,
null
);
}
}
joram/a3/common/src/main/java/fr/dyade/aaa/common/Arrays.java
0 → 100644
View file @
2a5a4aa5
/*
* Copyright (C) 1996 - 2000 BULL
* Copyright (C) 1996 - 2000 INRIA
*
* 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.
*/
package
fr.dyade.aaa.common
;
/**
* This class contains various methods for sorting and searching int arrays.
*/
public
class
Arrays
{
/**
* Sorts the specified array of ints into ascending numerical order.
* The sorting algorithm is a tuned quicksort.
*
* @param a the array to be sorted.
*/
public
static
void
sort
(
short
[]
a
)
{
sort1
(
a
,
0
,
a
.
length
);
}
/**
* Sorts the specified range of the specified array of ints into
* ascending numerical order.
*/
public
static
void
sort
(
short
[]
a
,
int
fromIndex
,
int
toIndex
)
{
rangeCheck
(
a
.
length
,
fromIndex
,
toIndex
);
sort1
(
a
,
fromIndex
,
toIndex
-
fromIndex
);
}
/**
* Sorts the specified sub-array of integers into ascending order.
*/
private
static
void
sort1
(
short
x
[],
int
off
,
int
len
)
{
// Insertion sort on smallest arrays
if
(
len
<
7
)
{
for
(
int
i
=
off
;
i
<
len
+
off
;
i
++)
for
(
int
j
=
i
;
j
>
off
&&
x
[
j
-
1
]>
x
[
j
];
j
--)
swap
(
x
,
j
,
j
-
1
);
return
;
}
// Choose a partition element, v
int
m
=
off
+
len
/
2
;
// Small arrays, middle element
if
(
len
>
7
)
{
int
l
=
off
;
int
n
=
off
+
len
-
1
;
if
(
len
>
40
)
{
// Big arrays, pseudomedian of 9
int
s
=
len
/
8
;
l
=
med3
(
x
,
l
,
l
+
s
,
l
+
2
*
s
);
m
=
med3
(
x
,
m
-
s
,
m
,
m
+
s
);
n
=
med3
(
x
,
n
-
2
*
s
,
n
-
s
,
n
);
}
m
=
med3
(
x
,
l
,
m
,
n
);
// Mid-size, med of 3
}
int
v
=
x
[
m
];
// Establish Invariant: v* (<v)* (>v)* v*
int
a
=
off
,
b
=
a
,
c
=
off
+
len
-
1
,
d
=
c
;
while
(
true
)
{
while
(
b
<=
c
&&
x
[
b
]
<=
v
)
{
if
(
x
[
b
]
==
v
)
swap
(
x
,
a
++,
b
);
b
++;
}
while
(
c
>=
b
&&
x
[
c
]
>=
v
)
{
if
(
x
[
c
]
==
v
)
swap
(
x
,
c
,
d
--);
c
--;
}
if
(
b
>
c
)
break
;
swap
(
x
,
b
++,
c
--);
}
// Swap partition elements back to middle
int
s
,
n
=
off
+
len
;
s
=
Math
.
min
(
a
-
off
,
b
-
a
);
vecswap
(
x
,
off
,
b
-
s
,
s
);
s
=
Math
.
min
(
d
-
c
,
n
-
d
-
1
);
vecswap
(
x
,
b
,
n
-
s
,
s
);
// Recursively sort non-partition-elements
if
((
s
=
b
-
a
)
>
1
)
sort1
(
x
,
off
,
s
);
if
((
s
=
d
-
c
)
>
1
)
sort1
(
x
,
n
-
s
,
s
);
}
/**
* Swaps x[a] with x[b].
*/
private
static
void
swap
(
short
x
[],
int
a
,
int
b
)
{
short
t
=
x
[
a
];
x
[
a
]
=
x
[
b
];
x
[
b
]
=
t
;
}
/**
* Swaps x[a .. (a+n-1)] with x[b .. (b+n-1)].
*/
private
static
void
vecswap
(
short
x
[],
int
a
,
int
b
,
int
n
)
{
for
(
int
i
=
0
;
i
<
n
;
i
++,
a
++,
b
++)
swap
(
x
,
a
,
b
);
}
/**
* Returns the index of the median of the three indexed integers.
*/
private
static
int
med3
(
short
x
[],
int
a
,
int
b
,
int
c
)
{
return
(
x
[
a
]
<
x
[
b
]
?
(
x
[
b
]
<
x
[
c
]
?
b
:
x
[
a
]
<
x
[
c
]
?
c
:
a
)
:
(
x
[
b
]
>
x
[
c
]
?
b
:
x
[
a
]
>
x
[
c
]
?
c
:
a
));
}
/**
* Check that fromIndex and toIndex are in range, and throw an
* appropriate exception if they aren't.
*/
private
static
void
rangeCheck
(
int
arrayLen
,
int
fromIndex
,
int
toIndex
)
{
if
(
fromIndex
>
toIndex
)
throw
new
IllegalArgumentException
(
"fromIndex("
+
fromIndex
+
") > toIndex("
+
toIndex
+
")"
);
if
(
fromIndex
<
0
)
throw
new
ArrayIndexOutOfBoundsException
(
fromIndex
);
if
(
toIndex
>
arrayLen
)
throw
new
ArrayIndexOutOfBoundsException
(
toIndex
);
}
/**
* Searches the specified array of ints for the specified value using the
* binary search algorithm. The array <strong>must</strong> be sorted (as
* by the <tt>sort</tt> method, above) prior to making this call.
*/
public
static
int
binarySearch
(
short
[]
a
,
int
key
)
{
int
low
=
0
;
int
high
=
a
.
length
-
1
;
while
(
low
<=
high
)
{
int
mid
=(
low
+
high
)/
2
;
int
midVal
=
a
[
mid
];
if
(
midVal
<
key
)
low
=
mid
+
1
;
else
if
(
midVal
>
key
)
high
=
mid
-
1
;
else
return
mid
;
// key found
}
return
-(
low
+
1
);
// key not found.
}
/**
* Returns <tt>true</tt> if the two specified arrays of shorts are
* <i>equal</i> to one another.
*/
public
static
boolean
equals
(
short
[]
a
,
short
a2
[])
{
if
(
a
==
a2
)
return
true
;
if
(
a
==
null
||
a2
==
null
)
return
false
;
int
length
=
a
.
length
;
if
(
a2
.
length
!=
length
)
return
false
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
if
(
a
[
i
]
!=
a2
[
i
])
return
false
;
return
true
;
}
}
joram/a3/common/src/main/java/fr/dyade/aaa/common/BinaryDump.java
0 → 100644
View file @
2a5a4aa5
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2008 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.common
;
import
java.text.DecimalFormat
;
/**
*
*/
public
class
BinaryDump
{
public
static
final
String
EOL
=
System
.
getProperty
(
"line.separator"
);
private
static
final
char
_hexcodes
[]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
};
private
static
final
int
_shifts
[]
=
{
60
,
56
,
52
,
48
,
44
,
40
,
36
,
32
,
28
,
24
,
20
,
16
,
12
,
8
,
4
,
0
};
/**
* dump an array of bytes to a String
*
* @param data the byte array to be dumped
* @param offset its offset, whatever that might mean
* @param index initial index into the byte array
*
* @exception ArrayIndexOutOfBoundsException if the index is
* outside the data array's bounds
* @return output string
*/
public
static
String
dump
(
final
byte
[]
data
,
final
long
offset
,
final
int
index
)
{
if
((
index
<
0
)
||
(
index
>=
data
.
length
))
throw
new
ArrayIndexOutOfBoundsException
(
"illegal index: "
+
index
+
", length="
+
data
.
length
);
long
display_offset
=
offset
+
index
;
StringBuffer
buffer
=
new
StringBuffer
(
74
);
for
(
int
j
=
index
;
j
<
data
.
length
;
j
+=
16
)
{
int
chars_read
=
data
.
length
-
j
;
if
(
chars_read
>
16
)
{
chars_read
=
16
;
}
buffer
.
append
(
dump
(
display_offset
)).
append
(
' '
);
for
(
int
k
=
0
;
k
<
16
;
k
++)
{
if
(
k
<
chars_read
)
{
buffer
.
append
(
dump
(
data
[
k
+
j
]));
}
else
{
buffer
.
append
(
" "
);
}
buffer
.
append
(
' '
);
}
for
(
int
k
=
0
;
k
<
chars_read
;
k
++)
{
if
((
data
[
k
+
j
]
>=
' '
)
&&
(
data
[
k
+
j
]
<
127
))
{
buffer
.
append
((
char
)
data
[
k
+
j
]);
}
else
{
buffer
.
append
(
'.'
);
}
}
buffer
.
append
(
EOL
);
display_offset
+=
chars_read
;
}
return
buffer
.
toString
();
}
private
static
String
dump
(
final
long
value
)
{
StringBuffer
buf
=
new
StringBuffer
();
buf
.
setLength
(
0
);
for
(
int
j
=
0
;
j
<
8
;
j
++)
{
buf
.
append
(
_hexcodes
[
((
int
)
(
value
>>
_shifts
[
j
+
_shifts
.
length
-
8
]))
&
15
]);
}
return
buf
.
toString
();
}
private
static
String
dump
(
final
byte
value
)
{
StringBuffer
buf
=
new
StringBuffer
();
buf
.
setLength
(
0
);
for
(
int
j
=
0
;
j
<
2
;
j
++)
{
buf
.
append
(
_hexcodes
[
(
value
>>
_shifts
[
j
+
6
])
&
15
]);
}
return
buf
.
toString
();
}
/**
* Dumps the byte array in hexadecimal format.
*
* @param value The value to convert
* @return A String representing the array of bytes
*/
public
static
String
toHex
(
final
byte
[]
value
)
{
return
toHex
(
value
,
0
,
value
.
length
);
}
/**
* dump an array of bytes to a String
*
* @param data the byte array to be dumped
* @param offset its offset, whatever that might mean
* @param index initial index into the byte array
*
* @exception ArrayIndexOutOfBoundsException if the index is
* outside the data array's bounds
* @return output string
*/
public
static
String
toHex
(
final
byte
[]
value
,
int
offset
,
int
length
)
{
StringBuffer
strbuf
=
new
StringBuffer
();
strbuf
.
append
(
'['
);
for
(
int
i
=
offset
;
i
<
offset
+
length
;
i
++)
{
strbuf
.
append
(
toHex
(
value
[
i
]));
strbuf
.
append
(
", "
);
}
strbuf
.
append
(
']'
);
return
strbuf
.
toString
();
}
/**
* Converts the parameter to a hex value breaking the results into lines.
*
* @param value The value to convert
* @param bytesPerLine The maximum number of bytes per line. The next byte
* will be written to a new line
* @return A String representing the array of bytes
*/
public
static
String
toHex
(
final
byte
[]
value
,
final
int
bytesPerLine
)
{
final
int
digits
=
(
int
)
Math
.
round
(
Math
.
log
(
value
.
length
)
/
Math
.
log
(
10
)
+
0.5
);
final
StringBuffer
formatString
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
digits
;
i
++)
formatString
.
append
(
'0'
);
formatString
.
append
(
": "
);
final
DecimalFormat
format
=
new
DecimalFormat
(
formatString
.
toString
());
StringBuffer
retVal
=
new
StringBuffer
();
retVal
.
append
(
format
.
format
(
0
));
int
i
=
-
1
;
for
(
int
x
=
0
;
x
<
value
.
length
;
x
++)
{
if
(++
i
==
bytesPerLine
)
{
retVal
.
append
(
'\n'
);