Revision: 22321
Author: brainslog
Date: Tue Apr 10 20:54:04 2012
Log: Fixing "Print Diameter Stack version on startup/stop"
Fixes Issue 3179
http://code.google.com/p/mobicents/source/detail?r=22321
Added:
/trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/VersionProperties.java
/trunk/servers/diameter/core/jdiameter/impl/src/main/resources/META-INF/version.properties
Modified:
/trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/StackImpl.java
=======================================
--- /dev/null
+++
/trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/VersionProperties.java
Tue Apr 10 20:54:04 2012
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jdiameter.client.impl;
+
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ *
+ * @author <a href="mailto:[email protected]"> Bartosz Baranowski </a>
+ * @author <a href="mailto:[email protected]"> Alexandre Mendonca </a>
+ */
+public class VersionProperties {
+
+ /**
+ * The single instance.
+ */
+ public final static VersionProperties instance = new VersionProperties();
+
+ /**
+ * The version properties.
+ */
+ private Properties props;
+
+ /**
+ * Do not allow direct public construction.
+ */
+ private VersionProperties() {
+ props = loadProperties();
+ }
+
+ /**
+ * Returns an unmodifiable map of version properties.
+ *
+ * @return
+ */
+ public Map getProperties() {
+ return Collections.unmodifiableMap(props);
+ }
+
+ /**
+ * Returns the value for the given property name.
+ *
+ * @param name
+ * - The name of the property.
+ * @return The property value or null if the property is not set.
+ */
+ public String getProperty(final String name) {
+ return props.getProperty(name);
+ }
+
+ /**
+ * Returns the version information as a string.
+ *
+ * @return Basic information as a string.
+ */
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ for (Object key : props.keySet()) {
+ if (first) {
+ first = false;
+ }
+ else {
+ sb.append(" , ");
+ }
+ sb.append(key).append(" = ").append(props.get(key));
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Load the version properties from a resource.
+ */
+ private Properties loadProperties() {
+
+ props = new Properties();
+
+ try {
+ InputStream in =
VersionProperties.class.getResourceAsStream("/META-INF/version.properties");
+ props.load(in);
+ in.close();
+ }
+ catch (Exception e) {
+ // failed to load version properties. go with defaults
+ props.put("vendor", "Mobicents");
+ props.put("version", "UN.DEFINED");
+ }
+
+ return props;
+ }
+
+}
=======================================
--- /dev/null
+++
/trunk/servers/diameter/core/jdiameter/impl/src/main/resources/META-INF/version.properties
Tue Apr 10 20:54:04 2012
@@ -0,0 +1,2 @@
+version=${pom.version}
+vendor=${vendor}
=======================================
---
/trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/StackImpl.java
Mon Mar 12 14:23:47 2012
+++
/trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/StackImpl.java
Tue Apr 10 20:54:04 2012
@@ -86,7 +86,6 @@
protected StackState state = StackState.IDLE;
protected Lock lock = new ReentrantLock();
-
/**
* Use for processing request time-out tasks (for all active peers)
*/
@@ -95,6 +94,9 @@
@SuppressWarnings("unchecked")
public SessionFactory init(Configuration config) throws
IllegalDiameterStateException, InternalException {
lock.lock();
+ if (log.isInfoEnabled()) {
+ log.info("(:)(:)(:)(:)(:) Starting " +
VersionProperties.instance.getProperty("vendor") + " DIAMETER Stack v" +
VersionProperties.instance.getProperty("version") + " (:)(:)(:)(:)(:)");
+ }
try {
if (state != StackState.IDLE) {
throw new IllegalDiameterStateException();
@@ -122,12 +124,14 @@
ValidatorLevel validatorSendLevel =
ValidatorLevel.fromString((String)
Parameters.DictionarySendLevel.defValue());
ValidatorLevel validatorReceiveLevel =
ValidatorLevel.fromString((String)
Parameters.DictionaryReceiveLevel.defValue());
- if(dictionaryConfigs != null && dictionaryConfigs.length > 0) {
+ if (dictionaryConfigs != null && dictionaryConfigs.length > 0) {
Configuration dictionaryConfiguration = dictionaryConfigs[0];
dictionaryClassName =
dictionaryConfiguration.getStringValue(Parameters.DictionaryClass.ordinal(),
(String) Parameters.DictionaryClass.defValue());
validatorEnabled =
dictionaryConfiguration.getBooleanValue(Parameters.DictionaryEnabled.ordinal(),
(Boolean) Parameters.DictionaryEnabled.defValue());
- validatorSendLevel =
ValidatorLevel.fromString(dictionaryConfiguration.getStringValue(Parameters.DictionarySendLevel.ordinal(),
(String) Parameters.DictionarySendLevel.defValue()));
- validatorReceiveLevel = ValidatorLevel.fromString(
dictionaryConfiguration.getStringValue(Parameters.DictionaryReceiveLevel.ordinal(),
(String) Parameters.DictionaryReceiveLevel.defValue()));
+ validatorSendLevel =
ValidatorLevel.fromString(dictionaryConfiguration.getStringValue(Parameters.DictionarySendLevel.ordinal(),
+ (String) Parameters.DictionarySendLevel.defValue()));
+ validatorReceiveLevel =
ValidatorLevel.fromString(dictionaryConfiguration.getStringValue(Parameters.DictionaryReceiveLevel.ordinal(),
+ (String) Parameters.DictionaryReceiveLevel.defValue()));
}
createDictionary(dictionaryClassName, validatorEnabled,
validatorSendLevel, validatorReceiveLevel);
@@ -145,10 +149,14 @@
finally {
lock.unlock();
}
+ if (log.isInfoEnabled()) {
+ log.info("(:)(:)(:)(:)(:) Started " +
VersionProperties.instance.getProperty("vendor") + " DIAMETER Stack v" +
VersionProperties.instance.getProperty("version") + " (:)(:)(:)(:)(:)");
+ }
return (SessionFactory)
assembler.getComponentInstance(SessionFactory.class);
}
- private void createDictionary(String clazz, boolean validatorEnabled,
ValidatorLevel validatorSendLevel, ValidatorLevel validatorReceiveLevel)
throws InternalException {
+ private void createDictionary(String clazz, boolean validatorEnabled,
ValidatorLevel validatorSendLevel, ValidatorLevel validatorReceiveLevel)
+ throws InternalException {
// Defer call to singleton
DictionarySingleton.init(clazz, validatorEnabled, validatorSendLevel,
validatorReceiveLevel);
}
@@ -249,6 +257,9 @@
lock.lock();
try {
if (state == StackState.STARTED || state == StackState.CONFIGURED) {
+ if (log.isInfoEnabled()) {
+ log.info("(:)(:)(:)(:)(:) Stopping " +
VersionProperties.instance.getProperty("vendor") + " DIAMETER Stack v" +
VersionProperties.instance.getProperty("version") + " (:)(:)(:)(:)(:)");
+ }
List<Peer> peerTable = peerManager.getPeerTable();
final CountDownLatch barrier = new
CountDownLatch(peerTable.size());
StateChangeListener listener = new AbstractStateChangeListener() {
@@ -304,6 +315,9 @@
log.warn("Stopped error", e);
}
state = StackState.STOPPED;
+ if (log.isInfoEnabled()) {
+ log.info("(:)(:)(:)(:)(:) Stopped " +
VersionProperties.instance.getProperty("vendor") + " DIAMETER Stack v" +
VersionProperties.instance.getProperty("version") + " (:)(:)(:)(:)(:)");
+ }
}
}
finally {
@@ -313,7 +327,7 @@
public void destroy() {
// Be friendly
- if(state == StackState.STARTED) {
+ if (state == StackState.STARTED) {
log.warn("Calling destroy() with Stack in STARTED state. Calling
stop(REBOOTING) before, please do it yourself with the proper cause.");
stop(DisconnectCause.REBOOTING);
}
@@ -383,7 +397,7 @@
if (aClass == PeerTable.class) {
unwrapObject = assembler.getComponentInstance(aClass);
}
- //TODO: "layers" should be removed....
+ // TODO: "layers" should be removed....
if (unwrapObject == null) {
unwrapObject =
assembler.getChilds()[StackLayer.id()].getComponentInstance(aClass);
}
@@ -438,7 +452,7 @@
try {
return getMetaData().toString();
}
- catch(Exception exc) {
+ catch (Exception exc) {
return "not set";
}
}