You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by dd...@apache.org on 2015/03/13 18:28:06 UTC
phoenix git commit: PHOENIX-1725. Addendum. Committing files I missed
earlier. Extract changes applicable to 4.0 branch (Jeffrey Zhong and Devaraj
Das)
Repository: phoenix
Updated Branches:
refs/heads/master e910d8d24 -> 94ade6ad4
PHOENIX-1725. Addendum. Committing files I missed earlier. Extract changes applicable to 4.0 branch (Jeffrey Zhong and Devaraj Das)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/94ade6ad
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/94ade6ad
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/94ade6ad
Branch: refs/heads/master
Commit: 94ade6ad4fa10c75b83bf72db71b86f2084fa8b6
Parents: e910d8d
Author: Devaraj Das <dd...@apache.org>
Authored: Fri Mar 13 10:27:51 2015 -0700
Committer: Devaraj Das <dd...@apache.org>
Committed: Fri Mar 13 10:27:51 2015 -0700
----------------------------------------------------------------------
.../phoenix/util/DefaultEnvironmentEdge.java | 34 +++++++++
.../apache/phoenix/util/EnvironmentEdge.java | 34 +++++++++
.../phoenix/util/EnvironmentEdgeManager.java | 74 ++++++++++++++++++++
3 files changed, 142 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/94ade6ad/phoenix-core/src/main/java/org/apache/phoenix/util/DefaultEnvironmentEdge.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/DefaultEnvironmentEdge.java b/phoenix-core/src/main/java/org/apache/phoenix/util/DefaultEnvironmentEdge.java
new file mode 100644
index 0000000..6f917e3
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/DefaultEnvironmentEdge.java
@@ -0,0 +1,34 @@
+/*
+ *
+ * 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.phoenix.util;
+
+/**
+ * Default implementation of an environment edge.
+ */
+public class DefaultEnvironmentEdge implements EnvironmentEdge {
+ /**
+ * {@inheritDoc}
+ * <p/>
+ * This implementation returns {@link System#currentTimeMillis()}
+ */
+ @Override
+ public long currentTime() {
+ return System.currentTimeMillis();
+ }
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/94ade6ad/phoenix-core/src/main/java/org/apache/phoenix/util/EnvironmentEdge.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/EnvironmentEdge.java b/phoenix-core/src/main/java/org/apache/phoenix/util/EnvironmentEdge.java
new file mode 100644
index 0000000..2610c5c
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/EnvironmentEdge.java
@@ -0,0 +1,34 @@
+/*
+ *
+ * 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.phoenix.util;
+
+/**
+ * Has some basic interaction with the environment. Alternate implementations
+ * can be used where required (eg in tests).
+ *
+ * @see EnvironmentEdgeManager
+ */
+public interface EnvironmentEdge {
+ /**
+ * Returns the currentTime.
+ *
+ * @return Current time.
+ */
+ long currentTime();
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/94ade6ad/phoenix-core/src/main/java/org/apache/phoenix/util/EnvironmentEdgeManager.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/EnvironmentEdgeManager.java b/phoenix-core/src/main/java/org/apache/phoenix/util/EnvironmentEdgeManager.java
new file mode 100644
index 0000000..04d3bd3
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/EnvironmentEdgeManager.java
@@ -0,0 +1,74 @@
+/*
+ *
+ * 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.phoenix.util;
+
+/**
+ * Manages a singleton instance of the environment edge. This class shall
+ * implement static versions of the interface {@link EnvironmentEdge}, then
+ * defer to the delegate on invocation.
+ */
+public class EnvironmentEdgeManager {
+ private static volatile EnvironmentEdge delegate = new DefaultEnvironmentEdge();
+
+ private EnvironmentEdgeManager() {
+
+ }
+
+ /**
+ * Retrieves the singleton instance of the {@link EnvironmentEdge} that is
+ * being managed.
+ *
+ * @return the edge.
+ */
+ public static EnvironmentEdge getDelegate() {
+ return delegate;
+ }
+
+ /**
+ * Resets the managed instance to the default instance: {@link
+ * DefaultEnvironmentEdge}.
+ */
+ public static void reset() {
+ injectEdge(new DefaultEnvironmentEdge());
+ }
+
+ /**
+ * Injects the given edge such that it becomes the managed entity. If null is
+ * passed to this method, the default type is assigned to the delegate.
+ *
+ * @param edge the new edge.
+ */
+ public static void injectEdge(EnvironmentEdge edge) {
+ if (edge == null) {
+ reset();
+ } else {
+ delegate = edge;
+ }
+ }
+
+ /**
+ * Defers to the delegate and calls the
+ * {@link EnvironmentEdge#currentTime()} method.
+ *
+ * @return current time in millis according to the delegate.
+ */
+ public static long currentTimeMillis() {
+ return getDelegate().currentTime();
+ }
+}