Discussion:
[3/4] git commit: Add Comparator for @Order-annotated classes.
Remko Popma
2014-09-24 06:49:51 UTC
Permalink
Request: is it possible to rename Order to SortOrder?
I associate orders with commercial transactions (buy Order, sell Order).

Sent from my iPhone
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/4aa329af
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/4aa329af
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/4aa329af
Branch: refs/heads/master
Commit: 4aa329af77abd498fb8791fdad640e120ccf2b54
Parents: b61f6f9
Authored: Sun Sep 21 21:20:53 2014 -0500
Committed: Wed Sep 24 00:03:01 2014 -0500
----------------------------------------------------------------------
.../apache/logging/log4j/core/config/Order.java | 4 +++
.../log4j/core/config/OrderComparator.java | 4 +--
log4j-core/src/test/resources/log4j-webvar.xml | 29 --------------------
log4j-web/src/test/resources/log4j-webvar.xml | 29 ++++++++++++++++++++
4 files changed, 35 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4aa329af/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Order.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Order.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Order.java
index eadc931..f7f8e4e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Order.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Order.java
@@ -27,5 +27,9 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
+ /**
+ * The priority of this annotated type. Larger numbers indicate lower priority with a lowest priority of
+ */
int value();
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4aa329af/log4j-core/src/main/java/org/apache/logging/log4j/core/config/OrderComparator.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/OrderComparator.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/OrderComparator.java
index 8c8abdd..e9fce18 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/OrderComparator.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/OrderComparator.java
@@ -15,7 +15,7 @@ public class OrderComparator implements Comparator<Class<?>> {
final Order lhsOrder = Assert.requireNonNull(lhs, "lhs").getAnnotation(Order.class);
final Order rhsOrder = Assert.requireNonNull(rhs, "rhs").getAnnotation(Order.class);
if (lhsOrder == null && rhsOrder == null) {
- // both unannotated means we can't really compare them
+ // both unannotated means equal priority
return 0;
}
@@ -25,7 +25,7 @@ public class OrderComparator implements Comparator<Class<?>> {
if (lhsOrder == null) {
return 1;
}
- // larger value means higher priority
+ // larger value means lower priority
return Integer.signum(rhsOrder.value() - lhsOrder.value());
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4aa329af/log4j-core/src/test/resources/log4j-webvar.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-webvar.xml b/log4j-core/src/test/resources/log4j-webvar.xml
deleted file mode 100644
index de3777a..0000000
--- a/log4j-core/src/test/resources/log4j-webvar.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF 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.
- -->
-<Configuration status="OFF">
- <Appenders>
- <File name="file" fileName="${web:initParam.myapp.logdir}/myapp.log" append="true">
- <PatternLayout pattern="%d [%t] %-5p %c - %m%n"/>
- </File>
- </Appenders>
- <Loggers>
- <Root level="warn">
- <AppenderRef ref="file"/>
- </Root>
- </Loggers>
-</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4aa329af/log4j-web/src/test/resources/log4j-webvar.xml
----------------------------------------------------------------------
diff --git a/log4j-web/src/test/resources/log4j-webvar.xml b/log4j-web/src/test/resources/log4j-webvar.xml
new file mode 100644
index 0000000..de3777a
--- /dev/null
+++ b/log4j-web/src/test/resources/log4j-webvar.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF 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.
+ -->
+<Configuration status="OFF">
+ <Appenders>
+ <File name="file" fileName="${web:initParam.myapp.logdir}/myapp.log" append="true">
+ <PatternLayout pattern="%d [%t] %-5p %c - %m%n"/>
+ </File>
+ </Appenders>
+ <Loggers>
+ <Root level="warn">
+ <AppenderRef ref="file"/>
+ </Root>
+ </Loggers>
+</Configuration>
\ No newline at end of file
Remko Popma
2014-09-24 06:54:58 UTC
Permalink
Never mind; I thought this was a new addition. I now realize the Order
annotation has been there for a long time and renaming it would impact
existing configurations. This is not my intention, so please disregard my
previous message.
Post by Remko Popma
Request: is it possible to rename Order to SortOrder?
I associate orders with commercial transactions (buy Order, sell Order).
Sent from my iPhone
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/4aa329af
http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/4aa329af
http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/4aa329af
Branch: refs/heads/master
Commit: 4aa329af77abd498fb8791fdad640e120ccf2b54
Parents: b61f6f9
Authored: Sun Sep 21 21:20:53 2014 -0500
Committed: Wed Sep 24 00:03:01 2014 -0500
----------------------------------------------------------------------
.../apache/logging/log4j/core/config/Order.java | 4 +++
.../log4j/core/config/OrderComparator.java | 4 +--
log4j-core/src/test/resources/log4j-webvar.xml | 29 --------------------
log4j-web/src/test/resources/log4j-webvar.xml | 29 ++++++++++++++++++++
4 files changed, 35 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4aa329af/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Order.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Order.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Order.java
index eadc931..f7f8e4e 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Order.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Order.java
@@ -27,5 +27,9 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
+ /**
+ * The priority of this annotated type. Larger numbers indicate
lower priority with a lowest priority of
+ */
int value();
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4aa329af/log4j-core/src/main/java/org/apache/logging/log4j/core/config/OrderComparator.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/OrderComparator.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/OrderComparator.java
index 8c8abdd..e9fce18 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/OrderComparator.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/OrderComparator.java
@@ -15,7 +15,7 @@ public class OrderComparator implements
Comparator<Class<?>> {
final Order lhsOrder = Assert.requireNonNull(lhs,
"lhs").getAnnotation(Order.class);
final Order rhsOrder = Assert.requireNonNull(rhs,
"rhs").getAnnotation(Order.class);
if (lhsOrder == null && rhsOrder == null) {
- // both unannotated means we can't really compare them
+ // both unannotated means equal priority
return 0;
}
@@ -25,7 +25,7 @@ public class OrderComparator implements
Comparator<Class<?>> {
if (lhsOrder == null) {
return 1;
}
- // larger value means higher priority
+ // larger value means lower priority
return Integer.signum(rhsOrder.value() - lhsOrder.value());
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4aa329af/log4j-core/src/test/resources/log4j-webvar.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-webvar.xml
b/log4j-core/src/test/resources/log4j-webvar.xml
deleted file mode 100644
index de3777a..0000000
--- a/log4j-core/src/test/resources/log4j-webvar.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF 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.
- -->
-<Configuration status="OFF">
- <Appenders>
- <File name="file"
fileName="${web:initParam.myapp.logdir}/myapp.log" append="true">
- <PatternLayout pattern="%d [%t] %-5p %c - %m%n"/>
- </File>
- </Appenders>
- <Loggers>
- <Root level="warn">
- <AppenderRef ref="file"/>
- </Root>
- </Loggers>
-</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4aa329af/log4j-web/src/test/resources/log4j-webvar.xml
----------------------------------------------------------------------
diff --git a/log4j-web/src/test/resources/log4j-webvar.xml
b/log4j-web/src/test/resources/log4j-webvar.xml
new file mode 100644
index 0000000..de3777a
--- /dev/null
+++ b/log4j-web/src/test/resources/log4j-webvar.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF 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.
+ -->
+<Configuration status="OFF">
+ <Appenders>
+ <File name="file"
fileName="${web:initParam.myapp.logdir}/myapp.log" append="true">
+ <PatternLayout pattern="%d [%t] %-5p %c - %m%n"/>
+ </File>
+ </Appenders>
+ <Loggers>
+ <Root level="warn">
+ <AppenderRef ref="file"/>
+ </Root>
+ </Loggers>
+</Configuration>
\ No newline at end of file
Matt Sicker
2014-09-24 13:11:41 UTC
Permalink
Note that Spring has the same annotation, but they use a default order
value of Integer.MAX_VALUE. In this case, I even put an unannotated class
as lower priority than that.

Also, I think I can update how the weighted ConfigurationFactory lookup.
Would be nice in 2.2 to support it in general for plugins (see LOG4J2-745).
Post by Remko Popma
Never mind; I thought this was a new addition. I now realize the Order
annotation has been there for a long time and renaming it would impact
existing configurations. This is not my intention, so please disregard my
previous message.
Post by Remko Popma
Request: is it possible to rename Order to SortOrder?
I associate orders with commercial transactions (buy Order, sell Order).
Sent from my iPhone
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/4aa329af
http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/4aa329af
http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/4aa329af
Branch: refs/heads/master
Commit: 4aa329af77abd498fb8791fdad640e120ccf2b54
Parents: b61f6f9
Authored: Sun Sep 21 21:20:53 2014 -0500
Committed: Wed Sep 24 00:03:01 2014 -0500
----------------------------------------------------------------------
.../apache/logging/log4j/core/config/Order.java | 4 +++
.../log4j/core/config/OrderComparator.java | 4 +--
log4j-core/src/test/resources/log4j-webvar.xml | 29
--------------------
log4j-web/src/test/resources/log4j-webvar.xml | 29
++++++++++++++++++++
4 files changed, 35 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4aa329af/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Order.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Order.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Order.java
index eadc931..f7f8e4e 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Order.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Order.java
@@ -27,5 +27,9 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
+ /**
+ * The priority of this annotated type. Larger numbers indicate
lower priority with a lowest priority of
+ */
int value();
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4aa329af/log4j-core/src/main/java/org/apache/logging/log4j/core/config/OrderComparator.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/OrderComparator.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/OrderComparator.java
index 8c8abdd..e9fce18 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/OrderComparator.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/OrderComparator.java
@@ -15,7 +15,7 @@ public class OrderComparator implements
Comparator<Class<?>> {
final Order lhsOrder = Assert.requireNonNull(lhs,
"lhs").getAnnotation(Order.class);
final Order rhsOrder = Assert.requireNonNull(rhs,
"rhs").getAnnotation(Order.class);
if (lhsOrder == null && rhsOrder == null) {
- // both unannotated means we can't really compare them
+ // both unannotated means equal priority
return 0;
}
@@ -25,7 +25,7 @@ public class OrderComparator implements
Comparator<Class<?>> {
if (lhsOrder == null) {
return 1;
}
- // larger value means higher priority
+ // larger value means lower priority
return Integer.signum(rhsOrder.value() - lhsOrder.value());
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4aa329af/log4j-core/src/test/resources/log4j-webvar.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-webvar.xml
b/log4j-core/src/test/resources/log4j-webvar.xml
deleted file mode 100644
index de3777a..0000000
--- a/log4j-core/src/test/resources/log4j-webvar.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed
with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF 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.
- -->
-<Configuration status="OFF">
- <Appenders>
- <File name="file"
fileName="${web:initParam.myapp.logdir}/myapp.log" append="true">
- <PatternLayout pattern="%d [%t] %-5p %c - %m%n"/>
- </File>
- </Appenders>
- <Loggers>
- <Root level="warn">
- <AppenderRef ref="file"/>
- </Root>
- </Loggers>
-</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4aa329af/log4j-web/src/test/resources/log4j-webvar.xml
----------------------------------------------------------------------
diff --git a/log4j-web/src/test/resources/log4j-webvar.xml
b/log4j-web/src/test/resources/log4j-webvar.xml
new file mode 100644
index 0000000..de3777a
--- /dev/null
+++ b/log4j-web/src/test/resources/log4j-webvar.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed
with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF 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.
+ -->
+<Configuration status="OFF">
+ <Appenders>
+ <File name="file"
fileName="${web:initParam.myapp.logdir}/myapp.log" append="true">
+ <PatternLayout pattern="%d [%t] %-5p %c - %m%n"/>
+ </File>
+ </Appenders>
+ <Loggers>
+ <Root level="warn">
+ <AppenderRef ref="file"/>
+ </Root>
+ </Loggers>
+</Configuration>
\ No newline at end of file
--
Matt Sicker <***@gmail.com>
Gary Gregory
2014-09-24 11:37:21 UTC
Permalink
Do we really want two LifeCycle abstract classes?

Will this not be a case -- like plug in builders vs. factory methods --
where we have two ways of doing the same thing?

When do I use one vs. the other? You'd need to Javadoc that at least.

Shouldn't we just have one way of doing this?

Gary
---------- Forwarded message ----------
From: <***@apache.org>
Date: Wed, Sep 24, 2014 at 1:39 AM
Subject: [2/4] git commit: Add LifeCycle abstract class that uses
AtomicReference.
To: ***@logging.apache.org


Add LifeCycle abstract class that uses AtomicReference.


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit:
http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1a332afa
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1a332afa
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1a332afa

Branch: refs/heads/master
Commit: 1a332afa33c55a72ae8ab5ec83cd5964de3fdc67
Parents: b701951
Author: Matt Sicker <***@apache.org>
Authored: Sun Sep 21 20:30:50 2014 -0500
Committer: Matt Sicker <***@apache.org>
Committed: Tue Sep 23 23:32:49 2014 -0500

----------------------------------------------------------------------
.../log4j/core/AbstractAtomicLifeCycle.java | 102 +++++++++++++++++++
.../apache/logging/log4j/core/LifeCycle.java | 9 +-
2 files changed, 108 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
new file mode 100644
index 0000000..05a343a
--- /dev/null
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
@@ -0,0 +1,102 @@
+package org.apache.logging.log4j.core;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.logging.log4j.core.util.Throwables;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * An extensible {@link LifeCycle} using an {@link AtomicReference} to
wrap its {@link LifeCycle.State}. Thus, classes
+ * which extend this class will follow the finite state machine as follows:
+ * <ol>
+ * <li>When {@link #start()} is called, {@link #doStart()} is called if
and only if this is in the INITIALIZED state or
+ * the STOPPED state.</li>
+ * <li>Before {@link #doStart()} is called, this will be in the STARTING
state.</li>
+ * <li>After {@link #doStart()} is called, this will be in the STARTED
state if no exception was thrown; otherwise,
+ * this will be in the INITIALIZED state again, and the exception thrown
will be re-thrown (if unchecked) or wrapped
+ * in an {@link java.lang.reflect.UndeclaredThrowableException} and then
rethrown (if checked).</li>
+ * <li>When {@link #stop()} is called, {@link #doStop()} is called if and
only if this is in the STARTED state.</li>
+ * <li>Before {@link #doStop()} is called, this will be in the STOPPING
state.</li>
+ * <li>After {@link #doStop()} is called, this will be in the STOPPED
state. Any exceptions thrown will be re-thrown
+ * as described above.</li>
+ * </ol>
+ *
+ * @since 2.1
+ */
+public abstract class AbstractAtomicLifeCycle implements LifeCycle,
Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected static final StatusLogger LOGGER = StatusLogger.getLogger();
+
+ private final AtomicReference<State> state = new
AtomicReference<State>(State.INITIALIZED);
+
+ @Override
+ public void start() {
+ if (state.compareAndSet(State.INITIALIZED, State.STARTING) ||
+ state.compareAndSet(State.STOPPED, State.STARTING)) {
+ try {
+ doStart();
+ state.set(State.STARTED);
+ } catch (final Exception e) {
+ state.set(State.INITIALIZED);
+ Throwables.rethrow(e);
+ }
+ }
+ }
+
+ /**
+ * Performs the start-up logic. This method is called only if this is
in the INITIALIZED or STOPPED state.
+ *
+ * @throws Exception
+ */
+ protected abstract void doStart() throws Exception;
+
+ @Override
+ public void stop() {
+ if (state.compareAndSet(State.STARTED, State.STOPPING)) {
+ try {
+ doStop();
+ } catch (Exception e) {
+ Throwables.rethrow(e);
+ } finally {
+ state.set(State.STOPPED);
+ }
+ }
+ }
+
+ /**
+ * Performs the tear-down logic. This method is called only if this is
in the STARTED state.
+ *
+ * @throws Exception
+ */
+ protected abstract void doStop() throws Exception;
+
+ @Override
+ public boolean isStarted() {
+ return state.get() == State.STARTED;
+ }
+
+ @Override
+ public boolean isStopped() {
+ return state.get() == State.STOPPED;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final AbstractAtomicLifeCycle that = (AbstractAtomicLifeCycle) o;
+ return state.equals(that.state);
+ }
+
+ @Override
+ public int hashCode() {
+ return state.hashCode();
+ }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
index e75ebd5..191edcd 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
@@ -18,7 +18,7 @@
package org.apache.logging.log4j.core;

/**
- * All proper Java frameworks implement some sort of object life cycle. In
Log4j, the main interface for handling
+ * Generic object life cycle support interface. In Log4j, the main
interface for handling
* the life cycle context of an object is this one. An object first starts
in the {@link State#INITIALIZED} state
* by default to indicate the class has been loaded. From here, calling
the {@link #start()} method will change this
* state to {@link State#STARTING}. After successfully being started, this
state is changed to {@link State#STARTED}.
@@ -26,9 +26,12 @@ package org.apache.logging.log4j.core;
* stopped, this goes into the {@link State#STOPPED} state. In most
circumstances, implementation classes should
* store their {@link State} in a {@code volatile} field or inside an
* {@link java.util.concurrent.atomic.AtomicReference} dependant on
synchronization and concurrency requirements.
+ *
+ * @see AbstractLifeCycle
+ * @see AbstractAtomicLifeCycle
*/
public interface LifeCycle {
-
+
/**
* Status of a life cycle like a {@link LoggerContext}.
*/
@@ -44,7 +47,7 @@ public interface LifeCycle {
/** Has stopped. */
STOPPED
}
-
+
void start();

void stop();
--
E-Mail: ***@gmail.com | ***@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Gary Gregory
2014-09-24 11:43:53 UTC
Permalink
Hm... and why does start() behave differently in AALC from ALC? AALC is not
used either... so... what is it in there for?

Gary
Post by Gary Gregory
Do we really want two LifeCycle abstract classes?
Will this not be a case -- like plug in builders vs. factory methods --
where we have two ways of doing the same thing?
When do I use one vs. the other? You'd need to Javadoc that at least.
Shouldn't we just have one way of doing this?
Gary
---------- Forwarded message ----------
Date: Wed, Sep 24, 2014 at 1:39 AM
Subject: [2/4] git commit: Add LifeCycle abstract class that uses
AtomicReference.
Add LifeCycle abstract class that uses AtomicReference.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1a332afa
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1a332afa
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1a332afa
Branch: refs/heads/master
Commit: 1a332afa33c55a72ae8ab5ec83cd5964de3fdc67
Parents: b701951
Authored: Sun Sep 21 20:30:50 2014 -0500
Committed: Tue Sep 23 23:32:49 2014 -0500
----------------------------------------------------------------------
.../log4j/core/AbstractAtomicLifeCycle.java | 102 +++++++++++++++++++
.../apache/logging/log4j/core/LifeCycle.java | 9 +-
2 files changed, 108 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
new file mode 100644
index 0000000..05a343a
--- /dev/null
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
@@ -0,0 +1,102 @@
+package org.apache.logging.log4j.core;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.logging.log4j.core.util.Throwables;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * <ol>
and only if this is in the INITIALIZED state or
+ * the STOPPED state.</li>
state.</li>
state if no exception was thrown; otherwise,
+ * this will be in the INITIALIZED state again, and the exception thrown
will be re-thrown (if unchecked) or wrapped
rethrown (if checked).</li>
only if this is in the STARTED state.</li>
state.</li>
state. Any exceptions thrown will be re-thrown
+ * as described above.</li>
+ * </ol>
+ *
+ */
+public abstract class AbstractAtomicLifeCycle implements LifeCycle,
Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected static final StatusLogger LOGGER = StatusLogger.getLogger();
+
+ private final AtomicReference<State> state = new
AtomicReference<State>(State.INITIALIZED);
+
+ public void start() {
+ if (state.compareAndSet(State.INITIALIZED, State.STARTING) ||
+ state.compareAndSet(State.STOPPED, State.STARTING)) {
+ try {
+ doStart();
+ state.set(State.STARTED);
+ } catch (final Exception e) {
+ state.set(State.INITIALIZED);
+ Throwables.rethrow(e);
+ }
+ }
+ }
+
+ /**
+ * Performs the start-up logic. This method is called only if this is
in the INITIALIZED or STOPPED state.
+ *
+ */
+ protected abstract void doStart() throws Exception;
+
+ public void stop() {
+ if (state.compareAndSet(State.STARTED, State.STOPPING)) {
+ try {
+ doStop();
+ } catch (Exception e) {
+ Throwables.rethrow(e);
+ } finally {
+ state.set(State.STOPPED);
+ }
+ }
+ }
+
+ /**
+ * Performs the tear-down logic. This method is called only if this
is in the STARTED state.
+ *
+ */
+ protected abstract void doStop() throws Exception;
+
+ public boolean isStarted() {
+ return state.get() == State.STARTED;
+ }
+
+ public boolean isStopped() {
+ return state.get() == State.STOPPED;
+ }
+
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final AbstractAtomicLifeCycle that = (AbstractAtomicLifeCycle) o;
+ return state.equals(that.state);
+ }
+
+ public int hashCode() {
+ return state.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
index e75ebd5..191edcd 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
@@ -18,7 +18,7 @@
package org.apache.logging.log4j.core;
/**
- * All proper Java frameworks implement some sort of object life cycle.
In Log4j, the main interface for handling
+ * Generic object life cycle support interface. In Log4j, the main
interface for handling
* the life cycle context of an object is this one. An object first
* by default to indicate the class has been loaded. From here, calling
@@ -26,9 +26,12 @@ package org.apache.logging.log4j.core;
circumstances, implementation classes should
synchronization and concurrency requirements.
+ *
*/
public interface LifeCycle {
-
+
/**
*/
@@ -44,7 +47,7 @@ public interface LifeCycle {
/** Has stopped. */
STOPPED
}
-
+
void start();
void stop();
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
E-Mail: ***@gmail.com | ***@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Matt Sicker
2014-09-24 13:07:36 UTC
Permalink
Looks like I meant to add this to a different branch. This is how I think
LifeCycle classes should work, though, so feedback would be good. If
possible, I'd like to replace the current ALC with the proposed AALC (which
would just be renamed to AbstractLifeCycle).
Post by Gary Gregory
Hm... and why does start() behave differently in AALC from ALC? AALC is
not used either... so... what is it in there for?
Gary
Post by Gary Gregory
Do we really want two LifeCycle abstract classes?
Will this not be a case -- like plug in builders vs. factory methods --
where we have two ways of doing the same thing?
When do I use one vs. the other? You'd need to Javadoc that at least.
Shouldn't we just have one way of doing this?
Gary
---------- Forwarded message ----------
Date: Wed, Sep 24, 2014 at 1:39 AM
Subject: [2/4] git commit: Add LifeCycle abstract class that uses
AtomicReference.
Add LifeCycle abstract class that uses AtomicReference.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1a332afa
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1a332afa
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1a332afa
Branch: refs/heads/master
Commit: 1a332afa33c55a72ae8ab5ec83cd5964de3fdc67
Parents: b701951
Authored: Sun Sep 21 20:30:50 2014 -0500
Committed: Tue Sep 23 23:32:49 2014 -0500
----------------------------------------------------------------------
.../log4j/core/AbstractAtomicLifeCycle.java | 102 +++++++++++++++++++
.../apache/logging/log4j/core/LifeCycle.java | 9 +-
2 files changed, 108 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
new file mode 100644
index 0000000..05a343a
--- /dev/null
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
@@ -0,0 +1,102 @@
+package org.apache.logging.log4j.core;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.logging.log4j.core.util.Throwables;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * <ol>
and only if this is in the INITIALIZED state or
+ * the STOPPED state.</li>
state.</li>
state if no exception was thrown; otherwise,
+ * this will be in the INITIALIZED state again, and the exception thrown
will be re-thrown (if unchecked) or wrapped
rethrown (if checked).</li>
and only if this is in the STARTED state.</li>
state.</li>
state. Any exceptions thrown will be re-thrown
+ * as described above.</li>
+ * </ol>
+ *
+ */
+public abstract class AbstractAtomicLifeCycle implements LifeCycle,
Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected static final StatusLogger LOGGER =
StatusLogger.getLogger();
+
+ private final AtomicReference<State> state = new
AtomicReference<State>(State.INITIALIZED);
+
+ public void start() {
+ if (state.compareAndSet(State.INITIALIZED, State.STARTING) ||
+ state.compareAndSet(State.STOPPED, State.STARTING)) {
+ try {
+ doStart();
+ state.set(State.STARTED);
+ } catch (final Exception e) {
+ state.set(State.INITIALIZED);
+ Throwables.rethrow(e);
+ }
+ }
+ }
+
+ /**
+ * Performs the start-up logic. This method is called only if this
is in the INITIALIZED or STOPPED state.
+ *
+ */
+ protected abstract void doStart() throws Exception;
+
+ public void stop() {
+ if (state.compareAndSet(State.STARTED, State.STOPPING)) {
+ try {
+ doStop();
+ } catch (Exception e) {
+ Throwables.rethrow(e);
+ } finally {
+ state.set(State.STOPPED);
+ }
+ }
+ }
+
+ /**
+ * Performs the tear-down logic. This method is called only if this
is in the STARTED state.
+ *
+ */
+ protected abstract void doStop() throws Exception;
+
+ public boolean isStarted() {
+ return state.get() == State.STARTED;
+ }
+
+ public boolean isStopped() {
+ return state.get() == State.STOPPED;
+ }
+
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final AbstractAtomicLifeCycle that = (AbstractAtomicLifeCycle) o;
+ return state.equals(that.state);
+ }
+
+ public int hashCode() {
+ return state.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
index e75ebd5..191edcd 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
@@ -18,7 +18,7 @@
package org.apache.logging.log4j.core;
/**
- * All proper Java frameworks implement some sort of object life cycle.
In Log4j, the main interface for handling
+ * Generic object life cycle support interface. In Log4j, the main
interface for handling
* the life cycle context of an object is this one. An object first
* by default to indicate the class has been loaded. From here, calling
@@ -26,9 +26,12 @@ package org.apache.logging.log4j.core;
circumstances, implementation classes should
synchronization and concurrency requirements.
+ *
*/
public interface LifeCycle {
-
+
/**
*/
@@ -44,7 +47,7 @@ public interface LifeCycle {
/** Has stopped. */
STOPPED
}
-
+
void start();
void stop();
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Matt Sicker <***@gmail.com>
Gary Gregory
2014-09-24 14:24:16 UTC
Permalink
Hm... so how do we pick one. Are there cases w/i Log4j where we'd want one
in one case and the other in another case?

Hm... I am warming up to having the same states as OSGi...

Gary
Post by Matt Sicker
Looks like I meant to add this to a different branch. This is how I think
LifeCycle classes should work, though, so feedback would be good. If
possible, I'd like to replace the current ALC with the proposed AALC (which
would just be renamed to AbstractLifeCycle).
Post by Gary Gregory
Hm... and why does start() behave differently in AALC from ALC? AALC is
not used either... so... what is it in there for?
Gary
Post by Gary Gregory
Do we really want two LifeCycle abstract classes?
Will this not be a case -- like plug in builders vs. factory methods --
where we have two ways of doing the same thing?
When do I use one vs. the other? You'd need to Javadoc that at least.
Shouldn't we just have one way of doing this?
Gary
---------- Forwarded message ----------
Date: Wed, Sep 24, 2014 at 1:39 AM
Subject: [2/4] git commit: Add LifeCycle abstract class that uses
AtomicReference.
Add LifeCycle abstract class that uses AtomicReference.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1a332afa
Branch: refs/heads/master
Commit: 1a332afa33c55a72ae8ab5ec83cd5964de3fdc67
Parents: b701951
Authored: Sun Sep 21 20:30:50 2014 -0500
Committed: Tue Sep 23 23:32:49 2014 -0500
----------------------------------------------------------------------
.../log4j/core/AbstractAtomicLifeCycle.java | 102
+++++++++++++++++++
.../apache/logging/log4j/core/LifeCycle.java | 9 +-
2 files changed, 108 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
new file mode 100644
index 0000000..05a343a
--- /dev/null
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
@@ -0,0 +1,102 @@
+package org.apache.logging.log4j.core;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.logging.log4j.core.util.Throwables;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * <ol>
and only if this is in the INITIALIZED state or
+ * the STOPPED state.</li>
STARTING state.</li>
state if no exception was thrown; otherwise,
+ * this will be in the INITIALIZED state again, and the exception
thrown will be re-thrown (if unchecked) or wrapped
then rethrown (if checked).</li>
and only if this is in the STARTED state.</li>
state.</li>
state. Any exceptions thrown will be re-thrown
+ * as described above.</li>
+ * </ol>
+ *
+ */
+public abstract class AbstractAtomicLifeCycle implements LifeCycle,
Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected static final StatusLogger LOGGER =
StatusLogger.getLogger();
+
+ private final AtomicReference<State> state = new
AtomicReference<State>(State.INITIALIZED);
+
+ public void start() {
+ if (state.compareAndSet(State.INITIALIZED, State.STARTING) ||
+ state.compareAndSet(State.STOPPED, State.STARTING)) {
+ try {
+ doStart();
+ state.set(State.STARTED);
+ } catch (final Exception e) {
+ state.set(State.INITIALIZED);
+ Throwables.rethrow(e);
+ }
+ }
+ }
+
+ /**
+ * Performs the start-up logic. This method is called only if this
is in the INITIALIZED or STOPPED state.
+ *
+ */
+ protected abstract void doStart() throws Exception;
+
+ public void stop() {
+ if (state.compareAndSet(State.STARTED, State.STOPPING)) {
+ try {
+ doStop();
+ } catch (Exception e) {
+ Throwables.rethrow(e);
+ } finally {
+ state.set(State.STOPPED);
+ }
+ }
+ }
+
+ /**
+ * Performs the tear-down logic. This method is called only if this
is in the STARTED state.
+ *
+ */
+ protected abstract void doStop() throws Exception;
+
+ public boolean isStarted() {
+ return state.get() == State.STARTED;
+ }
+
+ public boolean isStopped() {
+ return state.get() == State.STOPPED;
+ }
+
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final AbstractAtomicLifeCycle that = (AbstractAtomicLifeCycle) o;
+ return state.equals(that.state);
+ }
+
+ public int hashCode() {
+ return state.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
index e75ebd5..191edcd 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
@@ -18,7 +18,7 @@
package org.apache.logging.log4j.core;
/**
- * All proper Java frameworks implement some sort of object life cycle.
In Log4j, the main interface for handling
+ * Generic object life cycle support interface. In Log4j, the main
interface for handling
* the life cycle context of an object is this one. An object first
* by default to indicate the class has been loaded. From here, calling
@@ -26,9 +26,12 @@ package org.apache.logging.log4j.core;
circumstances, implementation classes should
synchronization and concurrency requirements.
+ *
*/
public interface LifeCycle {
-
+
/**
*/
@@ -44,7 +47,7 @@ public interface LifeCycle {
/** Has stopped. */
STOPPED
}
-
+
void start();
void stop();
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
--
E-Mail: ***@gmail.com | ***@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Matt Sicker
2014-09-24 14:59:17 UTC
Permalink
This implementation is threadsafe.
Post by Gary Gregory
Hm... so how do we pick one. Are there cases w/i Log4j where we'd want one
in one case and the other in another case?
Hm... I am warming up to having the same states as OSGi...
Gary
Post by Matt Sicker
Looks like I meant to add this to a different branch. This is how I think
LifeCycle classes should work, though, so feedback would be good. If
possible, I'd like to replace the current ALC with the proposed AALC (which
would just be renamed to AbstractLifeCycle).
Post by Gary Gregory
Hm... and why does start() behave differently in AALC from ALC? AALC is
not used either... so... what is it in there for?
Gary
Post by Gary Gregory
Do we really want two LifeCycle abstract classes?
Will this not be a case -- like plug in builders vs. factory methods --
where we have two ways of doing the same thing?
When do I use one vs. the other? You'd need to Javadoc that at least.
Shouldn't we just have one way of doing this?
Gary
---------- Forwarded message ----------
Date: Wed, Sep 24, 2014 at 1:39 AM
Subject: [2/4] git commit: Add LifeCycle abstract class that uses
AtomicReference.
Add LifeCycle abstract class that uses AtomicReference.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1a332afa
Branch: refs/heads/master
Commit: 1a332afa33c55a72ae8ab5ec83cd5964de3fdc67
Parents: b701951
Authored: Sun Sep 21 20:30:50 2014 -0500
Committed: Tue Sep 23 23:32:49 2014 -0500
----------------------------------------------------------------------
.../log4j/core/AbstractAtomicLifeCycle.java | 102
+++++++++++++++++++
.../apache/logging/log4j/core/LifeCycle.java | 9 +-
2 files changed, 108 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
new file mode 100644
index 0000000..05a343a
--- /dev/null
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
@@ -0,0 +1,102 @@
+package org.apache.logging.log4j.core;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.logging.log4j.core.util.Throwables;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * <ol>
if and only if this is in the INITIALIZED state or
+ * the STOPPED state.</li>
STARTING state.</li>
state if no exception was thrown; otherwise,
+ * this will be in the INITIALIZED state again, and the exception
thrown will be re-thrown (if unchecked) or wrapped
then rethrown (if checked).</li>
and only if this is in the STARTED state.</li>
STOPPING state.</li>
state. Any exceptions thrown will be re-thrown
+ * as described above.</li>
+ * </ol>
+ *
+ */
+public abstract class AbstractAtomicLifeCycle implements LifeCycle,
Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected static final StatusLogger LOGGER =
StatusLogger.getLogger();
+
+ private final AtomicReference<State> state = new
AtomicReference<State>(State.INITIALIZED);
+
+ public void start() {
+ if (state.compareAndSet(State.INITIALIZED, State.STARTING) ||
+ state.compareAndSet(State.STOPPED, State.STARTING)) {
+ try {
+ doStart();
+ state.set(State.STARTED);
+ } catch (final Exception e) {
+ state.set(State.INITIALIZED);
+ Throwables.rethrow(e);
+ }
+ }
+ }
+
+ /**
+ * Performs the start-up logic. This method is called only if this
is in the INITIALIZED or STOPPED state.
+ *
+ */
+ protected abstract void doStart() throws Exception;
+
+ public void stop() {
+ if (state.compareAndSet(State.STARTED, State.STOPPING)) {
+ try {
+ doStop();
+ } catch (Exception e) {
+ Throwables.rethrow(e);
+ } finally {
+ state.set(State.STOPPED);
+ }
+ }
+ }
+
+ /**
+ * Performs the tear-down logic. This method is called only if
this is in the STARTED state.
+ *
+ */
+ protected abstract void doStop() throws Exception;
+
+ public boolean isStarted() {
+ return state.get() == State.STARTED;
+ }
+
+ public boolean isStopped() {
+ return state.get() == State.STOPPED;
+ }
+
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final AbstractAtomicLifeCycle that = (AbstractAtomicLifeCycle) o;
+ return state.equals(that.state);
+ }
+
+ public int hashCode() {
+ return state.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
index e75ebd5..191edcd 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
@@ -18,7 +18,7 @@
package org.apache.logging.log4j.core;
/**
- * All proper Java frameworks implement some sort of object life
cycle. In Log4j, the main interface for handling
+ * Generic object life cycle support interface. In Log4j, the main
interface for handling
* the life cycle context of an object is this one. An object first
* by default to indicate the class has been loaded. From here,
@@ -26,9 +26,12 @@ package org.apache.logging.log4j.core;
circumstances, implementation classes should
synchronization and concurrency requirements.
+ *
*/
public interface LifeCycle {
-
+
/**
*/
@@ -44,7 +47,7 @@ public interface LifeCycle {
/** Has stopped. */
STOPPED
}
-
+
void start();
void stop();
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Matt Sicker <***@gmail.com>
Gary Gregory
2014-09-24 15:29:59 UTC
Permalink
How is the ACL not thread safe? I see that hashCode() could be an issue.

Gary
Post by Matt Sicker
This implementation is threadsafe.
Post by Gary Gregory
Hm... so how do we pick one. Are there cases w/i Log4j where we'd want
one in one case and the other in another case?
Hm... I am warming up to having the same states as OSGi...
Gary
Post by Matt Sicker
Looks like I meant to add this to a different branch. This is how I
think LifeCycle classes should work, though, so feedback would be good. If
possible, I'd like to replace the current ALC with the proposed AALC (which
would just be renamed to AbstractLifeCycle).
Post by Gary Gregory
Hm... and why does start() behave differently in AALC from ALC? AALC is
not used either... so... what is it in there for?
Gary
Post by Gary Gregory
Do we really want two LifeCycle abstract classes?
Will this not be a case -- like plug in builders vs. factory methods
-- where we have two ways of doing the same thing?
When do I use one vs. the other? You'd need to Javadoc that at least.
Shouldn't we just have one way of doing this?
Gary
---------- Forwarded message ----------
Date: Wed, Sep 24, 2014 at 1:39 AM
Subject: [2/4] git commit: Add LifeCycle abstract class that uses
AtomicReference.
Add LifeCycle abstract class that uses AtomicReference.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1a332afa
Branch: refs/heads/master
Commit: 1a332afa33c55a72ae8ab5ec83cd5964de3fdc67
Parents: b701951
Authored: Sun Sep 21 20:30:50 2014 -0500
Committed: Tue Sep 23 23:32:49 2014 -0500
----------------------------------------------------------------------
.../log4j/core/AbstractAtomicLifeCycle.java | 102
+++++++++++++++++++
.../apache/logging/log4j/core/LifeCycle.java | 9 +-
2 files changed, 108 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
new file mode 100644
index 0000000..05a343a
--- /dev/null
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
@@ -0,0 +1,102 @@
+package org.apache.logging.log4j.core;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.logging.log4j.core.util.Throwables;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * <ol>
if and only if this is in the INITIALIZED state or
+ * the STOPPED state.</li>
STARTING state.</li>
STARTED state if no exception was thrown; otherwise,
+ * this will be in the INITIALIZED state again, and the exception
thrown will be re-thrown (if unchecked) or wrapped
then rethrown (if checked).</li>
and only if this is in the STARTED state.</li>
STOPPING state.</li>
state. Any exceptions thrown will be re-thrown
+ * as described above.</li>
+ * </ol>
+ *
+ */
+public abstract class AbstractAtomicLifeCycle implements LifeCycle,
Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected static final StatusLogger LOGGER =
StatusLogger.getLogger();
+
+ private final AtomicReference<State> state = new
AtomicReference<State>(State.INITIALIZED);
+
+ public void start() {
+ if (state.compareAndSet(State.INITIALIZED, State.STARTING) ||
+ state.compareAndSet(State.STOPPED, State.STARTING)) {
+ try {
+ doStart();
+ state.set(State.STARTED);
+ } catch (final Exception e) {
+ state.set(State.INITIALIZED);
+ Throwables.rethrow(e);
+ }
+ }
+ }
+
+ /**
+ * Performs the start-up logic. This method is called only if
this is in the INITIALIZED or STOPPED state.
+ *
+ */
+ protected abstract void doStart() throws Exception;
+
+ public void stop() {
+ if (state.compareAndSet(State.STARTED, State.STOPPING)) {
+ try {
+ doStop();
+ } catch (Exception e) {
+ Throwables.rethrow(e);
+ } finally {
+ state.set(State.STOPPED);
+ }
+ }
+ }
+
+ /**
+ * Performs the tear-down logic. This method is called only if
this is in the STARTED state.
+ *
+ */
+ protected abstract void doStop() throws Exception;
+
+ public boolean isStarted() {
+ return state.get() == State.STARTED;
+ }
+
+ public boolean isStopped() {
+ return state.get() == State.STOPPED;
+ }
+
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final AbstractAtomicLifeCycle that =
(AbstractAtomicLifeCycle) o;
+ return state.equals(that.state);
+ }
+
+ public int hashCode() {
+ return state.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
index e75ebd5..191edcd 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
@@ -18,7 +18,7 @@
package org.apache.logging.log4j.core;
/**
- * All proper Java frameworks implement some sort of object life
cycle. In Log4j, the main interface for handling
+ * Generic object life cycle support interface. In Log4j, the main
interface for handling
* the life cycle context of an object is this one. An object first
* by default to indicate the class has been loaded. From here,
@@ -26,9 +26,12 @@ package org.apache.logging.log4j.core;
circumstances, implementation classes should
synchronization and concurrency requirements.
+ *
*/
public interface LifeCycle {
-
+
/**
*/
@@ -44,7 +47,7 @@ public interface LifeCycle {
/** Has stopped. */
STOPPED
}
-
+
void start();
void stop();
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
--
E-Mail: ***@gmail.com | ***@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Remko Popma
2014-09-24 16:03:18 UTC
Permalink
Post by Matt Sicker
Looks like I meant to add this to a different branch. This is how I think
LifeCycle classes should work, though, so feedback would be good. If
possible, I'd like to replace the current ALC with the proposed AALC (which
would just be renamed to AbstractLifeCycle).
Matt, if the intention was for this to go into a different branch, then
perhaps it is best to move these changes to a different branch. I haven't
had a chance to look at this in detail but it looks like quite a big change
to be making a few days before the release... For me I don't think this
week I'll be able to give it the time to review that it deserves...
Post by Matt Sicker
Post by Gary Gregory
Hm... and why does start() behave differently in AALC from ALC? AALC is
not used either... so... what is it in there for?
Gary
Post by Gary Gregory
Do we really want two LifeCycle abstract classes?
Will this not be a case -- like plug in builders vs. factory methods --
where we have two ways of doing the same thing?
When do I use one vs. the other? You'd need to Javadoc that at least.
Shouldn't we just have one way of doing this?
Gary
---------- Forwarded message ----------
Date: Wed, Sep 24, 2014 at 1:39 AM
Subject: [2/4] git commit: Add LifeCycle abstract class that uses
AtomicReference.
Add LifeCycle abstract class that uses AtomicReference.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1a332afa
Branch: refs/heads/master
Commit: 1a332afa33c55a72ae8ab5ec83cd5964de3fdc67
Parents: b701951
Authored: Sun Sep 21 20:30:50 2014 -0500
Committed: Tue Sep 23 23:32:49 2014 -0500
----------------------------------------------------------------------
.../log4j/core/AbstractAtomicLifeCycle.java | 102
+++++++++++++++++++
.../apache/logging/log4j/core/LifeCycle.java | 9 +-
2 files changed, 108 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
new file mode 100644
index 0000000..05a343a
--- /dev/null
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
@@ -0,0 +1,102 @@
+package org.apache.logging.log4j.core;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.logging.log4j.core.util.Throwables;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * <ol>
and only if this is in the INITIALIZED state or
+ * the STOPPED state.</li>
STARTING state.</li>
state if no exception was thrown; otherwise,
+ * this will be in the INITIALIZED state again, and the exception
thrown will be re-thrown (if unchecked) or wrapped
then rethrown (if checked).</li>
and only if this is in the STARTED state.</li>
state.</li>
state. Any exceptions thrown will be re-thrown
+ * as described above.</li>
+ * </ol>
+ *
+ */
+public abstract class AbstractAtomicLifeCycle implements LifeCycle,
Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected static final StatusLogger LOGGER =
StatusLogger.getLogger();
+
+ private final AtomicReference<State> state = new
AtomicReference<State>(State.INITIALIZED);
+
+ public void start() {
+ if (state.compareAndSet(State.INITIALIZED, State.STARTING) ||
+ state.compareAndSet(State.STOPPED, State.STARTING)) {
+ try {
+ doStart();
+ state.set(State.STARTED);
+ } catch (final Exception e) {
+ state.set(State.INITIALIZED);
+ Throwables.rethrow(e);
+ }
+ }
+ }
+
+ /**
+ * Performs the start-up logic. This method is called only if this
is in the INITIALIZED or STOPPED state.
+ *
+ */
+ protected abstract void doStart() throws Exception;
+
+ public void stop() {
+ if (state.compareAndSet(State.STARTED, State.STOPPING)) {
+ try {
+ doStop();
+ } catch (Exception e) {
+ Throwables.rethrow(e);
+ } finally {
+ state.set(State.STOPPED);
+ }
+ }
+ }
+
+ /**
+ * Performs the tear-down logic. This method is called only if this
is in the STARTED state.
+ *
+ */
+ protected abstract void doStop() throws Exception;
+
+ public boolean isStarted() {
+ return state.get() == State.STARTED;
+ }
+
+ public boolean isStopped() {
+ return state.get() == State.STOPPED;
+ }
+
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final AbstractAtomicLifeCycle that = (AbstractAtomicLifeCycle) o;
+ return state.equals(that.state);
+ }
+
+ public int hashCode() {
+ return state.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
index e75ebd5..191edcd 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
@@ -18,7 +18,7 @@
package org.apache.logging.log4j.core;
/**
- * All proper Java frameworks implement some sort of object life cycle.
In Log4j, the main interface for handling
+ * Generic object life cycle support interface. In Log4j, the main
interface for handling
* the life cycle context of an object is this one. An object first
* by default to indicate the class has been loaded. From here, calling
@@ -26,9 +26,12 @@ package org.apache.logging.log4j.core;
circumstances, implementation classes should
synchronization and concurrency requirements.
+ *
*/
public interface LifeCycle {
-
+
/**
*/
@@ -44,7 +47,7 @@ public interface LifeCycle {
/** Has stopped. */
STOPPED
}
-
+
void start();
void stop();
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Gary Gregory
2014-09-24 16:47:40 UTC
Permalink
Post by Remko Popma
Post by Matt Sicker
Looks like I meant to add this to a different branch. This is how I think
LifeCycle classes should work, though, so feedback would be good. If
possible, I'd like to replace the current ALC with the proposed AALC (which
would just be renamed to AbstractLifeCycle).
I have to agree here, this would be good to see in a branch for
consideration in 2.2. Especially since this is unlikely to be a drop-in
replacement.

Gary
Post by Remko Popma
Matt, if the intention was for this to go into a different branch, then
perhaps it is best to move these changes to a different branch. I haven't
had a chance to look at this in detail but it looks like quite a big change
to be making a few days before the release... For me I don't think this
week I'll be able to give it the time to review that it deserves...
Post by Matt Sicker
Post by Gary Gregory
Hm... and why does start() behave differently in AALC from ALC? AALC is
not used either... so... what is it in there for?
Gary
Post by Gary Gregory
Do we really want two LifeCycle abstract classes?
Will this not be a case -- like plug in builders vs. factory methods --
where we have two ways of doing the same thing?
When do I use one vs. the other? You'd need to Javadoc that at least.
Shouldn't we just have one way of doing this?
Gary
---------- Forwarded message ----------
Date: Wed, Sep 24, 2014 at 1:39 AM
Subject: [2/4] git commit: Add LifeCycle abstract class that uses
AtomicReference.
Add LifeCycle abstract class that uses AtomicReference.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1a332afa
Branch: refs/heads/master
Commit: 1a332afa33c55a72ae8ab5ec83cd5964de3fdc67
Parents: b701951
Authored: Sun Sep 21 20:30:50 2014 -0500
Committed: Tue Sep 23 23:32:49 2014 -0500
----------------------------------------------------------------------
.../log4j/core/AbstractAtomicLifeCycle.java | 102
+++++++++++++++++++
.../apache/logging/log4j/core/LifeCycle.java | 9 +-
2 files changed, 108 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
new file mode 100644
index 0000000..05a343a
--- /dev/null
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
@@ -0,0 +1,102 @@
+package org.apache.logging.log4j.core;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.logging.log4j.core.util.Throwables;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * <ol>
if and only if this is in the INITIALIZED state or
+ * the STOPPED state.</li>
STARTING state.</li>
state if no exception was thrown; otherwise,
+ * this will be in the INITIALIZED state again, and the exception
thrown will be re-thrown (if unchecked) or wrapped
then rethrown (if checked).</li>
and only if this is in the STARTED state.</li>
STOPPING state.</li>
state. Any exceptions thrown will be re-thrown
+ * as described above.</li>
+ * </ol>
+ *
+ */
+public abstract class AbstractAtomicLifeCycle implements LifeCycle,
Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected static final StatusLogger LOGGER =
StatusLogger.getLogger();
+
+ private final AtomicReference<State> state = new
AtomicReference<State>(State.INITIALIZED);
+
+ public void start() {
+ if (state.compareAndSet(State.INITIALIZED, State.STARTING) ||
+ state.compareAndSet(State.STOPPED, State.STARTING)) {
+ try {
+ doStart();
+ state.set(State.STARTED);
+ } catch (final Exception e) {
+ state.set(State.INITIALIZED);
+ Throwables.rethrow(e);
+ }
+ }
+ }
+
+ /**
+ * Performs the start-up logic. This method is called only if this
is in the INITIALIZED or STOPPED state.
+ *
+ */
+ protected abstract void doStart() throws Exception;
+
+ public void stop() {
+ if (state.compareAndSet(State.STARTED, State.STOPPING)) {
+ try {
+ doStop();
+ } catch (Exception e) {
+ Throwables.rethrow(e);
+ } finally {
+ state.set(State.STOPPED);
+ }
+ }
+ }
+
+ /**
+ * Performs the tear-down logic. This method is called only if
this is in the STARTED state.
+ *
+ */
+ protected abstract void doStop() throws Exception;
+
+ public boolean isStarted() {
+ return state.get() == State.STARTED;
+ }
+
+ public boolean isStopped() {
+ return state.get() == State.STOPPED;
+ }
+
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final AbstractAtomicLifeCycle that = (AbstractAtomicLifeCycle) o;
+ return state.equals(that.state);
+ }
+
+ public int hashCode() {
+ return state.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
index e75ebd5..191edcd 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
@@ -18,7 +18,7 @@
package org.apache.logging.log4j.core;
/**
- * All proper Java frameworks implement some sort of object life
cycle. In Log4j, the main interface for handling
+ * Generic object life cycle support interface. In Log4j, the main
interface for handling
* the life cycle context of an object is this one. An object first
* by default to indicate the class has been loaded. From here,
@@ -26,9 +26,12 @@ package org.apache.logging.log4j.core;
circumstances, implementation classes should
synchronization and concurrency requirements.
+ *
*/
public interface LifeCycle {
-
+
/**
*/
@@ -44,7 +47,7 @@ public interface LifeCycle {
/** Has stopped. */
STOPPED
}
-
+
void start();
void stop();
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
--
E-Mail: ***@gmail.com | ***@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Matt Sicker
2014-09-24 19:30:32 UTC
Permalink
I'll move it to a branch tonight, sorry about that. And I might be wrong
about thread safety, but using AtomicReference<State> seems to make more
sense.
Post by Gary Gregory
Post by Remko Popma
Post by Matt Sicker
Looks like I meant to add this to a different branch. This is how I
think LifeCycle classes should work, though, so feedback would be good. If
possible, I'd like to replace the current ALC with the proposed AALC (which
would just be renamed to AbstractLifeCycle).
I have to agree here, this would be good to see in a branch for
consideration in 2.2. Especially since this is unlikely to be a drop-in
replacement.
Gary
Post by Remko Popma
Matt, if the intention was for this to go into a different branch, then
perhaps it is best to move these changes to a different branch. I haven't
had a chance to look at this in detail but it looks like quite a big change
to be making a few days before the release... For me I don't think this
week I'll be able to give it the time to review that it deserves...
Post by Matt Sicker
Post by Gary Gregory
Hm... and why does start() behave differently in AALC from ALC? AALC is
not used either... so... what is it in there for?
Gary
Post by Gary Gregory
Do we really want two LifeCycle abstract classes?
Will this not be a case -- like plug in builders vs. factory methods
-- where we have two ways of doing the same thing?
When do I use one vs. the other? You'd need to Javadoc that at least.
Shouldn't we just have one way of doing this?
Gary
---------- Forwarded message ----------
Date: Wed, Sep 24, 2014 at 1:39 AM
Subject: [2/4] git commit: Add LifeCycle abstract class that uses
AtomicReference.
Add LifeCycle abstract class that uses AtomicReference.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1a332afa
Branch: refs/heads/master
Commit: 1a332afa33c55a72ae8ab5ec83cd5964de3fdc67
Parents: b701951
Authored: Sun Sep 21 20:30:50 2014 -0500
Committed: Tue Sep 23 23:32:49 2014 -0500
----------------------------------------------------------------------
.../log4j/core/AbstractAtomicLifeCycle.java | 102
+++++++++++++++++++
.../apache/logging/log4j/core/LifeCycle.java | 9 +-
2 files changed, 108 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
new file mode 100644
index 0000000..05a343a
--- /dev/null
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
@@ -0,0 +1,102 @@
+package org.apache.logging.log4j.core;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.logging.log4j.core.util.Throwables;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * <ol>
if and only if this is in the INITIALIZED state or
+ * the STOPPED state.</li>
STARTING state.</li>
STARTED state if no exception was thrown; otherwise,
+ * this will be in the INITIALIZED state again, and the exception
thrown will be re-thrown (if unchecked) or wrapped
then rethrown (if checked).</li>
and only if this is in the STARTED state.</li>
STOPPING state.</li>
state. Any exceptions thrown will be re-thrown
+ * as described above.</li>
+ * </ol>
+ *
+ */
+public abstract class AbstractAtomicLifeCycle implements LifeCycle,
Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected static final StatusLogger LOGGER =
StatusLogger.getLogger();
+
+ private final AtomicReference<State> state = new
AtomicReference<State>(State.INITIALIZED);
+
+ public void start() {
+ if (state.compareAndSet(State.INITIALIZED, State.STARTING) ||
+ state.compareAndSet(State.STOPPED, State.STARTING)) {
+ try {
+ doStart();
+ state.set(State.STARTED);
+ } catch (final Exception e) {
+ state.set(State.INITIALIZED);
+ Throwables.rethrow(e);
+ }
+ }
+ }
+
+ /**
+ * Performs the start-up logic. This method is called only if
this is in the INITIALIZED or STOPPED state.
+ *
+ */
+ protected abstract void doStart() throws Exception;
+
+ public void stop() {
+ if (state.compareAndSet(State.STARTED, State.STOPPING)) {
+ try {
+ doStop();
+ } catch (Exception e) {
+ Throwables.rethrow(e);
+ } finally {
+ state.set(State.STOPPED);
+ }
+ }
+ }
+
+ /**
+ * Performs the tear-down logic. This method is called only if
this is in the STARTED state.
+ *
+ */
+ protected abstract void doStop() throws Exception;
+
+ public boolean isStarted() {
+ return state.get() == State.STARTED;
+ }
+
+ public boolean isStopped() {
+ return state.get() == State.STOPPED;
+ }
+
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final AbstractAtomicLifeCycle that =
(AbstractAtomicLifeCycle) o;
+ return state.equals(that.state);
+ }
+
+ public int hashCode() {
+ return state.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
index e75ebd5..191edcd 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
@@ -18,7 +18,7 @@
package org.apache.logging.log4j.core;
/**
- * All proper Java frameworks implement some sort of object life
cycle. In Log4j, the main interface for handling
+ * Generic object life cycle support interface. In Log4j, the main
interface for handling
* the life cycle context of an object is this one. An object first
* by default to indicate the class has been loaded. From here,
@@ -26,9 +26,12 @@ package org.apache.logging.log4j.core;
circumstances, implementation classes should
synchronization and concurrency requirements.
+ *
*/
public interface LifeCycle {
-
+
/**
*/
@@ -44,7 +47,7 @@ public interface LifeCycle {
/** Has stopped. */
STOPPED
}
-
+
void start();
void stop();
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Matt Sicker <***@gmail.com>
Matt Sicker
2014-09-25 01:59:54 UTC
Permalink
Reverted the commit.
Post by Matt Sicker
I'll move it to a branch tonight, sorry about that. And I might be wrong
about thread safety, but using AtomicReference<State> seems to make more
sense.
Post by Gary Gregory
Post by Remko Popma
Post by Matt Sicker
Looks like I meant to add this to a different branch. This is how I
think LifeCycle classes should work, though, so feedback would be good. If
possible, I'd like to replace the current ALC with the proposed AALC (which
would just be renamed to AbstractLifeCycle).
I have to agree here, this would be good to see in a branch for
consideration in 2.2. Especially since this is unlikely to be a drop-in
replacement.
Gary
Post by Remko Popma
Matt, if the intention was for this to go into a different branch, then
perhaps it is best to move these changes to a different branch. I haven't
had a chance to look at this in detail but it looks like quite a big change
to be making a few days before the release... For me I don't think this
week I'll be able to give it the time to review that it deserves...
Post by Matt Sicker
Post by Gary Gregory
Hm... and why does start() behave differently in AALC from ALC? AALC
is not used either... so... what is it in there for?
Gary
Post by Gary Gregory
Do we really want two LifeCycle abstract classes?
Will this not be a case -- like plug in builders vs. factory methods
-- where we have two ways of doing the same thing?
When do I use one vs. the other? You'd need to Javadoc that at least.
Shouldn't we just have one way of doing this?
Gary
---------- Forwarded message ----------
Date: Wed, Sep 24, 2014 at 1:39 AM
Subject: [2/4] git commit: Add LifeCycle abstract class that uses
AtomicReference.
Add LifeCycle abstract class that uses AtomicReference.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1a332afa
Branch: refs/heads/master
Commit: 1a332afa33c55a72ae8ab5ec83cd5964de3fdc67
Parents: b701951
Authored: Sun Sep 21 20:30:50 2014 -0500
Committed: Tue Sep 23 23:32:49 2014 -0500
----------------------------------------------------------------------
.../log4j/core/AbstractAtomicLifeCycle.java | 102
+++++++++++++++++++
.../apache/logging/log4j/core/LifeCycle.java | 9 +-
2 files changed, 108 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
new file mode 100644
index 0000000..05a343a
--- /dev/null
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
@@ -0,0 +1,102 @@
+package org.apache.logging.log4j.core;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.logging.log4j.core.util.Throwables;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * <ol>
if and only if this is in the INITIALIZED state or
+ * the STOPPED state.</li>
STARTING state.</li>
STARTED state if no exception was thrown; otherwise,
+ * this will be in the INITIALIZED state again, and the exception
thrown will be re-thrown (if unchecked) or wrapped
then rethrown (if checked).</li>
if and only if this is in the STARTED state.</li>
STOPPING state.</li>
STOPPED state. Any exceptions thrown will be re-thrown
+ * as described above.</li>
+ * </ol>
+ *
+ */
+public abstract class AbstractAtomicLifeCycle implements LifeCycle,
Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected static final StatusLogger LOGGER =
StatusLogger.getLogger();
+
+ private final AtomicReference<State> state = new
AtomicReference<State>(State.INITIALIZED);
+
+ public void start() {
+ if (state.compareAndSet(State.INITIALIZED, State.STARTING) ||
+ state.compareAndSet(State.STOPPED, State.STARTING)) {
+ try {
+ doStart();
+ state.set(State.STARTED);
+ } catch (final Exception e) {
+ state.set(State.INITIALIZED);
+ Throwables.rethrow(e);
+ }
+ }
+ }
+
+ /**
+ * Performs the start-up logic. This method is called only if
this is in the INITIALIZED or STOPPED state.
+ *
+ */
+ protected abstract void doStart() throws Exception;
+
+ public void stop() {
+ if (state.compareAndSet(State.STARTED, State.STOPPING)) {
+ try {
+ doStop();
+ } catch (Exception e) {
+ Throwables.rethrow(e);
+ } finally {
+ state.set(State.STOPPED);
+ }
+ }
+ }
+
+ /**
+ * Performs the tear-down logic. This method is called only if
this is in the STARTED state.
+ *
+ */
+ protected abstract void doStop() throws Exception;
+
+ public boolean isStarted() {
+ return state.get() == State.STARTED;
+ }
+
+ public boolean isStopped() {
+ return state.get() == State.STOPPED;
+ }
+
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final AbstractAtomicLifeCycle that =
(AbstractAtomicLifeCycle) o;
+ return state.equals(that.state);
+ }
+
+ public int hashCode() {
+ return state.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
index e75ebd5..191edcd 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
@@ -18,7 +18,7 @@
package org.apache.logging.log4j.core;
/**
- * All proper Java frameworks implement some sort of object life
cycle. In Log4j, the main interface for handling
+ * Generic object life cycle support interface. In Log4j, the main
interface for handling
* the life cycle context of an object is this one. An object first
* by default to indicate the class has been loaded. From here,
@@ -26,9 +26,12 @@ package org.apache.logging.log4j.core;
circumstances, implementation classes should
synchronization and concurrency requirements.
+ *
*/
public interface LifeCycle {
-
+
/**
*/
@@ -44,7 +47,7 @@ public interface LifeCycle {
/** Has stopped. */
STOPPED
}
-
+
void start();
void stop();
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
--
Matt Sicker <***@gmail.com>
Gary Gregory
2014-09-25 02:07:43 UTC
Permalink
Revisit for 2.2...

Gary
Post by Matt Sicker
Reverted the commit.
Post by Matt Sicker
I'll move it to a branch tonight, sorry about that. And I might be wrong
about thread safety, but using AtomicReference<State> seems to make more
sense.
Post by Gary Gregory
Post by Remko Popma
Post by Matt Sicker
Looks like I meant to add this to a different branch. This is how I
think LifeCycle classes should work, though, so feedback would be good. If
possible, I'd like to replace the current ALC with the proposed AALC (which
would just be renamed to AbstractLifeCycle).
I have to agree here, this would be good to see in a branch for
consideration in 2.2. Especially since this is unlikely to be a drop-in
replacement.
Gary
Post by Remko Popma
Matt, if the intention was for this to go into a different branch, then
perhaps it is best to move these changes to a different branch. I haven't
had a chance to look at this in detail but it looks like quite a big change
to be making a few days before the release... For me I don't think this
week I'll be able to give it the time to review that it deserves...
Post by Matt Sicker
Post by Gary Gregory
Hm... and why does start() behave differently in AALC from ALC? AALC
is not used either... so... what is it in there for?
Gary
Post by Gary Gregory
Do we really want two LifeCycle abstract classes?
Will this not be a case -- like plug in builders vs. factory methods
-- where we have two ways of doing the same thing?
When do I use one vs. the other? You'd need to Javadoc that at least.
Shouldn't we just have one way of doing this?
Gary
---------- Forwarded message ----------
Date: Wed, Sep 24, 2014 at 1:39 AM
Subject: [2/4] git commit: Add LifeCycle abstract class that uses
AtomicReference.
Add LifeCycle abstract class that uses AtomicReference.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1a332afa
Branch: refs/heads/master
Commit: 1a332afa33c55a72ae8ab5ec83cd5964de3fdc67
Parents: b701951
Authored: Sun Sep 21 20:30:50 2014 -0500
Committed: Tue Sep 23 23:32:49 2014 -0500
----------------------------------------------------------------------
.../log4j/core/AbstractAtomicLifeCycle.java | 102
+++++++++++++++++++
.../apache/logging/log4j/core/LifeCycle.java | 9 +-
2 files changed, 108 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
new file mode 100644
index 0000000..05a343a
--- /dev/null
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
@@ -0,0 +1,102 @@
+package org.apache.logging.log4j.core;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.logging.log4j.core.util.Throwables;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * <ol>
called if and only if this is in the INITIALIZED state or
+ * the STOPPED state.</li>
STARTING state.</li>
STARTED state if no exception was thrown; otherwise,
+ * this will be in the INITIALIZED state again, and the exception
thrown will be re-thrown (if unchecked) or wrapped
then rethrown (if checked).</li>
if and only if this is in the STARTED state.</li>
STOPPING state.</li>
STOPPED state. Any exceptions thrown will be re-thrown
+ * as described above.</li>
+ * </ol>
+ *
+ */
+public abstract class AbstractAtomicLifeCycle implements LifeCycle,
Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected static final StatusLogger LOGGER =
StatusLogger.getLogger();
+
+ private final AtomicReference<State> state = new
AtomicReference<State>(State.INITIALIZED);
+
+ public void start() {
+ if (state.compareAndSet(State.INITIALIZED, State.STARTING) ||
+ state.compareAndSet(State.STOPPED, State.STARTING)) {
+ try {
+ doStart();
+ state.set(State.STARTED);
+ } catch (final Exception e) {
+ state.set(State.INITIALIZED);
+ Throwables.rethrow(e);
+ }
+ }
+ }
+
+ /**
+ * Performs the start-up logic. This method is called only if
this is in the INITIALIZED or STOPPED state.
+ *
+ */
+ protected abstract void doStart() throws Exception;
+
+ public void stop() {
+ if (state.compareAndSet(State.STARTED, State.STOPPING)) {
+ try {
+ doStop();
+ } catch (Exception e) {
+ Throwables.rethrow(e);
+ } finally {
+ state.set(State.STOPPED);
+ }
+ }
+ }
+
+ /**
+ * Performs the tear-down logic. This method is called only if
this is in the STARTED state.
+ *
+ */
+ protected abstract void doStop() throws Exception;
+
+ public boolean isStarted() {
+ return state.get() == State.STARTED;
+ }
+
+ public boolean isStopped() {
+ return state.get() == State.STOPPED;
+ }
+
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final AbstractAtomicLifeCycle that =
(AbstractAtomicLifeCycle) o;
+ return state.equals(that.state);
+ }
+
+ public int hashCode() {
+ return state.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
index e75ebd5..191edcd 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
@@ -18,7 +18,7 @@
package org.apache.logging.log4j.core;
/**
- * All proper Java frameworks implement some sort of object life
cycle. In Log4j, the main interface for handling
+ * Generic object life cycle support interface. In Log4j, the main
interface for handling
* the life cycle context of an object is this one. An object first
* by default to indicate the class has been loaded. From here,
@@ -26,9 +26,12 @@ package org.apache.logging.log4j.core;
circumstances, implementation classes should
synchronization and concurrency requirements.
+ *
*/
public interface LifeCycle {
-
+
/**
*/
@@ -44,7 +47,7 @@ public interface LifeCycle {
/** Has stopped. */
STOPPED
}
-
+
void start();
void stop();
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
--
--
E-Mail: ***@gmail.com | ***@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Matt Sicker
2014-09-25 02:13:11 UTC
Permalink
https://issues.apache.org/jira/browse/LOG4J2-859
Post by Gary Gregory
Revisit for 2.2...
Gary
Post by Matt Sicker
Reverted the commit.
Post by Matt Sicker
I'll move it to a branch tonight, sorry about that. And I might be wrong
about thread safety, but using AtomicReference<State> seems to make more
sense.
Post by Gary Gregory
Post by Remko Popma
Post by Matt Sicker
Looks like I meant to add this to a different branch. This is how I
think LifeCycle classes should work, though, so feedback would be good. If
possible, I'd like to replace the current ALC with the proposed AALC (which
would just be renamed to AbstractLifeCycle).
I have to agree here, this would be good to see in a branch for
consideration in 2.2. Especially since this is unlikely to be a drop-in
replacement.
Gary
Post by Remko Popma
Matt, if the intention was for this to go into a different branch,
then perhaps it is best to move these changes to a different branch. I
haven't had a chance to look at this in detail but it looks like quite a
big change to be making a few days before the release... For me I don't
think this week I'll be able to give it the time to review that it
deserves...
Post by Matt Sicker
Post by Gary Gregory
Hm... and why does start() behave differently in AALC from ALC? AALC
is not used either... so... what is it in there for?
Gary
On Wed, Sep 24, 2014 at 7:37 AM, Gary Gregory <
Post by Gary Gregory
Do we really want two LifeCycle abstract classes?
Will this not be a case -- like plug in builders vs. factory
methods -- where we have two ways of doing the same thing?
When do I use one vs. the other? You'd need to Javadoc that at least.
Shouldn't we just have one way of doing this?
Gary
---------- Forwarded message ----------
Date: Wed, Sep 24, 2014 at 1:39 AM
Subject: [2/4] git commit: Add LifeCycle abstract class that uses
AtomicReference.
Add LifeCycle abstract class that uses AtomicReference.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1a332afa
http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1a332afa
Branch: refs/heads/master
Commit: 1a332afa33c55a72ae8ab5ec83cd5964de3fdc67
Parents: b701951
Authored: Sun Sep 21 20:30:50 2014 -0500
Committed: Tue Sep 23 23:32:49 2014 -0500
----------------------------------------------------------------------
.../log4j/core/AbstractAtomicLifeCycle.java | 102
+++++++++++++++++++
.../apache/logging/log4j/core/LifeCycle.java | 9 +-
2 files changed, 108 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
new file mode 100644
index 0000000..05a343a
--- /dev/null
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractAtomicLifeCycle.java
@@ -0,0 +1,102 @@
+package org.apache.logging.log4j.core;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.logging.log4j.core.util.Throwables;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * <ol>
called if and only if this is in the INITIALIZED state or
+ * the STOPPED state.</li>
STARTING state.</li>
STARTED state if no exception was thrown; otherwise,
+ * this will be in the INITIALIZED state again, and the exception
thrown will be re-thrown (if unchecked) or wrapped
and then rethrown (if checked).</li>
if and only if this is in the STARTED state.</li>
STOPPING state.</li>
STOPPED state. Any exceptions thrown will be re-thrown
+ * as described above.</li>
+ * </ol>
+ *
+ */
+public abstract class AbstractAtomicLifeCycle implements
LifeCycle, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected static final StatusLogger LOGGER =
StatusLogger.getLogger();
+
+ private final AtomicReference<State> state = new
AtomicReference<State>(State.INITIALIZED);
+
+ public void start() {
+ if (state.compareAndSet(State.INITIALIZED, State.STARTING) ||
+ state.compareAndSet(State.STOPPED, State.STARTING)) {
+ try {
+ doStart();
+ state.set(State.STARTED);
+ } catch (final Exception e) {
+ state.set(State.INITIALIZED);
+ Throwables.rethrow(e);
+ }
+ }
+ }
+
+ /**
+ * Performs the start-up logic. This method is called only if
this is in the INITIALIZED or STOPPED state.
+ *
+ */
+ protected abstract void doStart() throws Exception;
+
+ public void stop() {
+ if (state.compareAndSet(State.STARTED, State.STOPPING)) {
+ try {
+ doStop();
+ } catch (Exception e) {
+ Throwables.rethrow(e);
+ } finally {
+ state.set(State.STOPPED);
+ }
+ }
+ }
+
+ /**
+ * Performs the tear-down logic. This method is called only if
this is in the STARTED state.
+ *
+ */
+ protected abstract void doStop() throws Exception;
+
+ public boolean isStarted() {
+ return state.get() == State.STARTED;
+ }
+
+ public boolean isStopped() {
+ return state.get() == State.STOPPED;
+ }
+
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final AbstractAtomicLifeCycle that =
(AbstractAtomicLifeCycle) o;
+ return state.equals(that.state);
+ }
+
+ public int hashCode() {
+ return state.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a332afa/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
index e75ebd5..191edcd 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle.java
@@ -18,7 +18,7 @@
package org.apache.logging.log4j.core;
/**
- * All proper Java frameworks implement some sort of object life
cycle. In Log4j, the main interface for handling
+ * Generic object life cycle support interface. In Log4j, the main
interface for handling
* the life cycle context of an object is this one. An object
* by default to indicate the class has been loaded. From here,
@@ -26,9 +26,12 @@ package org.apache.logging.log4j.core;
most circumstances, implementation classes should
on synchronization and concurrency requirements.
+ *
*/
public interface LifeCycle {
-
+
/**
*/
@@ -44,7 +47,7 @@ public interface LifeCycle {
/** Has stopped. */
STOPPED
}
-
+
void start();
void stop();
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
--
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Matt Sicker <***@gmail.com>
Loading...