You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by be...@apache.org on 2015/02/11 16:36:35 UTC
[1/3] cassandra git commit: Safer Resource Management++
Repository: cassandra
Updated Branches:
refs/heads/cassandra-2.1 857ee0ac3 -> 207751c8a
refs/heads/trunk 96866ce53 -> d73e7db80
Safer Resource Management++
patch by benedict; reviewed by marcus for CASSANDRA-8707
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/207751c8
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/207751c8
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/207751c8
Branch: refs/heads/cassandra-2.1
Commit: 207751c8ac9800b7e004ec72096c478a30aafebc
Parents: 857ee0a
Author: Benedict Elliott Smith <be...@apache.org>
Authored: Wed Feb 11 15:35:50 2015 +0000
Committer: Benedict Elliott Smith <be...@apache.org>
Committed: Wed Feb 11 15:35:50 2015 +0000
----------------------------------------------------------------------
.../utils/concurrent/SharedCloseable.java | 35 ++++++++++++++
.../utils/concurrent/SharedCloseableImpl.java | 47 ++++++++++++++++++
.../concurrent/WrappedSharedCloseable.java | 51 ++++++++++++++++++++
3 files changed, 133 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/207751c8/src/java/org/apache/cassandra/utils/concurrent/SharedCloseable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/concurrent/SharedCloseable.java b/src/java/org/apache/cassandra/utils/concurrent/SharedCloseable.java
new file mode 100644
index 0000000..1e5a026
--- /dev/null
+++ b/src/java/org/apache/cassandra/utils/concurrent/SharedCloseable.java
@@ -0,0 +1,35 @@
+/*
+* 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.
+*/
+package org.apache.cassandra.utils.concurrent;
+
+/**
+ * A simple extension of AutoCloseable, that represents a resource that can be utilised in multiple locations,
+ * each managing their own closure of the resource, so that when the last such instance is closed all are.
+ *
+ */
+public interface SharedCloseable extends AutoCloseable
+{
+ /**
+ * @return a new instance of the object representing the same state and backed by the same underlying resources.
+ * Coordinates with the original (and other instances) when the underlying resource should be closed.
+ * Throws an exception if the shared resource has already been closed.
+ */
+ public SharedCloseable sharedCopy();
+
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/207751c8/src/java/org/apache/cassandra/utils/concurrent/SharedCloseableImpl.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/concurrent/SharedCloseableImpl.java b/src/java/org/apache/cassandra/utils/concurrent/SharedCloseableImpl.java
new file mode 100644
index 0000000..0d3a843
--- /dev/null
+++ b/src/java/org/apache/cassandra/utils/concurrent/SharedCloseableImpl.java
@@ -0,0 +1,47 @@
+/*
+* 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.
+*/
+package org.apache.cassandra.utils.concurrent;
+
+/**
+ * A simple abstract implementation of SharedCloseable
+ */
+public abstract class SharedCloseableImpl implements SharedCloseable
+{
+ final Ref<?> ref;
+
+ public SharedCloseableImpl(RefCounted.Tidy tidy)
+ {
+ ref = new Ref<Object>(null, tidy);
+ }
+
+ protected SharedCloseableImpl(SharedCloseableImpl copy)
+ {
+ this.ref = copy.ref.ref();
+ }
+
+ public boolean isCleanedUp()
+ {
+ return ref.globalCount() == 0;
+ }
+
+ public void close()
+ {
+ ref.ensureReleased();
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/207751c8/src/java/org/apache/cassandra/utils/concurrent/WrappedSharedCloseable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/concurrent/WrappedSharedCloseable.java b/src/java/org/apache/cassandra/utils/concurrent/WrappedSharedCloseable.java
new file mode 100644
index 0000000..c656f28
--- /dev/null
+++ b/src/java/org/apache/cassandra/utils/concurrent/WrappedSharedCloseable.java
@@ -0,0 +1,51 @@
+/*
+* 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.
+*/
+package org.apache.cassandra.utils.concurrent;
+
+/**
+ * An implementation of SharedCloseable that wraps a normal AutoCloseable,
+ * ensuring its close method is only called when all instances of SharedCloseable have been
+ */
+public abstract class WrappedSharedCloseable extends SharedCloseableImpl
+{
+ final AutoCloseable wrapped;
+
+ public WrappedSharedCloseable(final AutoCloseable closeable)
+ {
+ super(new RefCounted.Tidy()
+ {
+ public void tidy() throws Exception
+ {
+ closeable.close();
+ }
+
+ public String name()
+ {
+ return closeable.toString();
+ }
+ });
+ wrapped = closeable;
+ }
+
+ protected WrappedSharedCloseable(WrappedSharedCloseable copy)
+ {
+ super(copy);
+ wrapped = copy.wrapped;
+ }
+}
[2/3] cassandra git commit: Safer Resource Management++
Posted by be...@apache.org.
Safer Resource Management++
patch by benedict; reviewed by marcus for CASSANDRA-8707
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/207751c8
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/207751c8
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/207751c8
Branch: refs/heads/trunk
Commit: 207751c8ac9800b7e004ec72096c478a30aafebc
Parents: 857ee0a
Author: Benedict Elliott Smith <be...@apache.org>
Authored: Wed Feb 11 15:35:50 2015 +0000
Committer: Benedict Elliott Smith <be...@apache.org>
Committed: Wed Feb 11 15:35:50 2015 +0000
----------------------------------------------------------------------
.../utils/concurrent/SharedCloseable.java | 35 ++++++++++++++
.../utils/concurrent/SharedCloseableImpl.java | 47 ++++++++++++++++++
.../concurrent/WrappedSharedCloseable.java | 51 ++++++++++++++++++++
3 files changed, 133 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/207751c8/src/java/org/apache/cassandra/utils/concurrent/SharedCloseable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/concurrent/SharedCloseable.java b/src/java/org/apache/cassandra/utils/concurrent/SharedCloseable.java
new file mode 100644
index 0000000..1e5a026
--- /dev/null
+++ b/src/java/org/apache/cassandra/utils/concurrent/SharedCloseable.java
@@ -0,0 +1,35 @@
+/*
+* 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.
+*/
+package org.apache.cassandra.utils.concurrent;
+
+/**
+ * A simple extension of AutoCloseable, that represents a resource that can be utilised in multiple locations,
+ * each managing their own closure of the resource, so that when the last such instance is closed all are.
+ *
+ */
+public interface SharedCloseable extends AutoCloseable
+{
+ /**
+ * @return a new instance of the object representing the same state and backed by the same underlying resources.
+ * Coordinates with the original (and other instances) when the underlying resource should be closed.
+ * Throws an exception if the shared resource has already been closed.
+ */
+ public SharedCloseable sharedCopy();
+
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/207751c8/src/java/org/apache/cassandra/utils/concurrent/SharedCloseableImpl.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/concurrent/SharedCloseableImpl.java b/src/java/org/apache/cassandra/utils/concurrent/SharedCloseableImpl.java
new file mode 100644
index 0000000..0d3a843
--- /dev/null
+++ b/src/java/org/apache/cassandra/utils/concurrent/SharedCloseableImpl.java
@@ -0,0 +1,47 @@
+/*
+* 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.
+*/
+package org.apache.cassandra.utils.concurrent;
+
+/**
+ * A simple abstract implementation of SharedCloseable
+ */
+public abstract class SharedCloseableImpl implements SharedCloseable
+{
+ final Ref<?> ref;
+
+ public SharedCloseableImpl(RefCounted.Tidy tidy)
+ {
+ ref = new Ref<Object>(null, tidy);
+ }
+
+ protected SharedCloseableImpl(SharedCloseableImpl copy)
+ {
+ this.ref = copy.ref.ref();
+ }
+
+ public boolean isCleanedUp()
+ {
+ return ref.globalCount() == 0;
+ }
+
+ public void close()
+ {
+ ref.ensureReleased();
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/207751c8/src/java/org/apache/cassandra/utils/concurrent/WrappedSharedCloseable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/concurrent/WrappedSharedCloseable.java b/src/java/org/apache/cassandra/utils/concurrent/WrappedSharedCloseable.java
new file mode 100644
index 0000000..c656f28
--- /dev/null
+++ b/src/java/org/apache/cassandra/utils/concurrent/WrappedSharedCloseable.java
@@ -0,0 +1,51 @@
+/*
+* 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.
+*/
+package org.apache.cassandra.utils.concurrent;
+
+/**
+ * An implementation of SharedCloseable that wraps a normal AutoCloseable,
+ * ensuring its close method is only called when all instances of SharedCloseable have been
+ */
+public abstract class WrappedSharedCloseable extends SharedCloseableImpl
+{
+ final AutoCloseable wrapped;
+
+ public WrappedSharedCloseable(final AutoCloseable closeable)
+ {
+ super(new RefCounted.Tidy()
+ {
+ public void tidy() throws Exception
+ {
+ closeable.close();
+ }
+
+ public String name()
+ {
+ return closeable.toString();
+ }
+ });
+ wrapped = closeable;
+ }
+
+ protected WrappedSharedCloseable(WrappedSharedCloseable copy)
+ {
+ super(copy);
+ wrapped = copy.wrapped;
+ }
+}
[3/3] cassandra git commit: Merge branch 'cassandra-2.1' into trunk
Posted by be...@apache.org.
Merge branch 'cassandra-2.1' into trunk
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/d73e7db8
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/d73e7db8
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/d73e7db8
Branch: refs/heads/trunk
Commit: d73e7db80b8c3cf4d982eedb456de5816e9958d2
Parents: 96866ce 207751c
Author: Benedict Elliott Smith <be...@apache.org>
Authored: Wed Feb 11 15:36:22 2015 +0000
Committer: Benedict Elliott Smith <be...@apache.org>
Committed: Wed Feb 11 15:36:22 2015 +0000
----------------------------------------------------------------------
.../utils/concurrent/SharedCloseable.java | 35 ++++++++++++++
.../utils/concurrent/SharedCloseableImpl.java | 47 ++++++++++++++++++
.../concurrent/WrappedSharedCloseable.java | 51 ++++++++++++++++++++
3 files changed, 133 insertions(+)
----------------------------------------------------------------------