[java-metadata-aggregator] branch master updated: MDA-137 command-line tool should shut down Spring context
Ian Young
ian at iay.org.uk
Thu Dec 3 10:28:39 EST 2015
This is an automated email from the git hooks/post-receive script.
iay pushed a commit to branch master
in repository java-metadata-aggregator.
The following commit(s) were added to refs/heads/master by this push:
new 7c5a837 MDA-137 command-line tool should shut down Spring context
7c5a837 is described below
commit 7c5a8378e86b694d9f396377f2644b169f1ef51e
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Thu Dec 3 15:29:48 2015 +0000
MDA-137 command-line tool should shut down Spring context
Includes a (very manual) test; details in MDA137Test-config.xml.
---
.../shibboleth/metadata/cli/SimpleCommandLine.java | 4 ++
.../net/shibboleth/metadata/cli/MDA137Stage.java | 52 ++++++++++++++++++++++
.../shibboleth/metadata/cli/MDA137Test-config.xml | 46 +++++++++++++++++++
3 files changed, 102 insertions(+)
diff --git a/aggregator-cli/src/main/java/net/shibboleth/metadata/cli/SimpleCommandLine.java b/aggregator-cli/src/main/java/net/shibboleth/metadata/cli/SimpleCommandLine.java
index dd8497a..f7f0bea 100644
--- a/aggregator-cli/src/main/java/net/shibboleth/metadata/cli/SimpleCommandLine.java
+++ b/aggregator-cli/src/main/java/net/shibboleth/metadata/cli/SimpleCommandLine.java
@@ -88,6 +88,10 @@ public final class SimpleCommandLine {
String fileUri = new File(cli.getInputFile()).toURI().toString();
log.debug("Initializing Spring context with configuration file {}", fileUri);
appCtx = new FileSystemXmlApplicationContext(fileUri);
+
+ // Register a shutdown hook for the context, so that beans will be
+ // correctly destroyed before the CLI exits.
+ appCtx.registerShutdownHook();
} catch (BeansException e) {
log.error("Unable to initialize Spring context", e);
System.exit(RC_INIT);
diff --git a/aggregator-cli/src/test/java/net/shibboleth/metadata/cli/MDA137Stage.java b/aggregator-cli/src/test/java/net/shibboleth/metadata/cli/MDA137Stage.java
new file mode 100644
index 0000000..752c2dd
--- /dev/null
+++ b/aggregator-cli/src/test/java/net/shibboleth/metadata/cli/MDA137Stage.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.metadata.cli;
+
+import java.util.Collection;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.pipeline.BaseStage;
+import net.shibboleth.metadata.pipeline.StageProcessingException;
+
+/**
+ * A stage which does nothing except be created and destroyed.
+ */
+public class MDA137Stage<T> extends BaseStage<T> {
+
+ /** Class logger. */
+ private final Logger log = LoggerFactory.getLogger(MDA137Stage.class);
+
+ @Override
+ protected void doExecute(Collection<Item<T>> itemCollection) throws StageProcessingException {
+ // Do absolutely nothing
+ }
+
+ @Override
+ protected void doInitialize() {
+ log.info("MDA-137 initialized");
+ }
+
+ @Override
+ protected void doDestroy() {
+ log.info("MDA-137 destroyed");
+ }
+
+}
diff --git a/aggregator-cli/src/test/resources/net/shibboleth/metadata/cli/MDA137Test-config.xml b/aggregator-cli/src/test/resources/net/shibboleth/metadata/cli/MDA137Test-config.xml
new file mode 100644
index 0000000..8ba9f4d
--- /dev/null
+++ b/aggregator-cli/src/test/resources/net/shibboleth/metadata/cli/MDA137Test-config.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Manual test for destructors being called on components in the created Spring context.
+
+ Run the MDA CLI in verbose mode with this configuration file and with MDA137Stage available in the classpath,
+ for example by copying the test jar into the library directory.
+
+ Failure: you see something like this:
+
+ MDA-137 initialized
+ Pipeline 'test' execution starting at Thu Dec 03 15:11:45 GMT 2015
+ Pipeline 'test' execution completed at Thu Dec 03 15:11:45 GMT 2015; run time 0.036 seconds
+
+ Success: you see an additional line "MDA-137 destroyed" after the pipeline execution has completed.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ default-lazy-init="true"
+ xmlns:c="http://www.springframework.org/schema/c"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
+
+ <bean id="component_parent" abstract="true"
+ init-method="initialize" destroy-method="destroy"/>
+
+ <bean id="stage_parent" abstract="true" parent="component_parent"/>
+
+ <bean id="SimplePipeline" abstract="true" parent="component_parent"
+ class="net.shibboleth.metadata.pipeline.SimplePipeline"/>
+
+ <bean id="test" p:id="test" parent="SimplePipeline">
+ <property name="stages">
+ <list>
+ <bean id="test" p:id="test" parent="stage_parent"
+ class="net.shibboleth.metadata.cli.MDA137Stage"/>
+ </list>
+ </property>
+ </bean>
+
+</beans>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list