You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/05/15 15:48:45 UTC
incubator-ignite git commit: # IGNITE-904: Implemented.
Repository: incubator-ignite
Updated Branches:
refs/heads/ignite-904 [created] eca8ea578
# IGNITE-904: Implemented.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/eca8ea57
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/eca8ea57
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/eca8ea57
Branch: refs/heads/ignite-904
Commit: eca8ea578201b7cf9ebfa3cea307996822d28c76
Parents: 04774b5f
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Fri May 15 16:47:57 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Fri May 15 16:47:57 2015 +0300
----------------------------------------------------------------------
.../org/apache/ignite/internal/IgnitionEx.java | 136 ++++++-------------
.../internal/interop/InteropBootstrap.java | 34 +++++
.../interop/InteropBootstrapFactory.java | 39 ++++++
.../internal/interop/InteropIgnition.java | 103 ++++++++++++++
.../internal/interop/InteropProcessor.java | 25 ++++
5 files changed, 240 insertions(+), 97 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/eca8ea57/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
index 8d88677..d54e06f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
@@ -532,22 +532,6 @@ public class IgnitionEx {
}
/**
- * Start Grid passing a closure which will modify configuration before it is passed to start routine.
- *
- * @param springCfgPath Spring config path.
- * @param gridName Grid name.
- * @param cfgClo Configuration closure.
- * @return Started Grid.
- * @throws IgniteCheckedException If failed.
- */
- public static Ignite startWithClosure(@Nullable String springCfgPath, @Nullable String gridName,
- IgniteClosure<IgniteConfiguration, IgniteConfiguration> cfgClo) throws IgniteCheckedException {
- URL url = U.resolveSpringUrl(springCfgPath);
-
- return start(url, gridName, null, cfgClo);
- }
-
- /**
* Loads all grid configurations specified within given Spring XML configuration file.
* <p>
* Usually Spring XML configuration file will contain only one Grid definition. Note that
@@ -734,7 +718,40 @@ public class IgnitionEx {
*/
public static Ignite start(URL springCfgUrl, @Nullable String gridName,
@Nullable GridSpringResourceContext springCtx) throws IgniteCheckedException {
- return start(springCfgUrl, gridName, springCtx, null);
+ A.notNull(springCfgUrl, "springCfgUrl");
+
+ boolean isLog4jUsed = U.gridClassLoader().getResource("org/apache/log4j/Appender.class") != null;
+
+ IgniteBiTuple<Object, Object> t = null;
+
+ if (isLog4jUsed) {
+ try {
+ t = U.addLog4jNoOpLogger();
+ }
+ catch (IgniteCheckedException ignore) {
+ isLog4jUsed = false;
+ }
+ }
+
+ Collection<Handler> savedHnds = null;
+
+ if (!isLog4jUsed)
+ savedHnds = U.addJavaNoOpLogger();
+
+ IgniteBiTuple<Collection<IgniteConfiguration>, ? extends GridSpringResourceContext> cfgMap;
+
+ try {
+ cfgMap = loadConfigurations(springCfgUrl);
+ }
+ finally {
+ if (isLog4jUsed && t != null)
+ U.removeLog4jNoOpLogger(t);
+
+ if (!isLog4jUsed)
+ U.removeJavaNoOpLogger(savedHnds);
+ }
+
+ return startConfigurations(cfgMap, springCfgUrl, gridName, springCtx);
}
/**
@@ -780,73 +797,6 @@ public class IgnitionEx {
*/
public static Ignite start(InputStream springCfgStream, @Nullable String gridName,
@Nullable GridSpringResourceContext springCtx) throws IgniteCheckedException {
- return start(springCfgStream, gridName, springCtx, null);
- }
-
- /**
- * Internal Spring-based start routine.
- *
- * @param springCfgUrl Spring XML configuration file URL. This cannot be {@code null}.
- * @param gridName Grid name that will override default.
- * @param springCtx Optional Spring application context.
- * @param cfgClo Optional closure to change configuration before it is used to start the grid.
- * @return Started grid.
- * @throws IgniteCheckedException If failed.
- */
- private static Ignite start(final URL springCfgUrl, @Nullable String gridName,
- @Nullable GridSpringResourceContext springCtx,
- @Nullable IgniteClosure<IgniteConfiguration, IgniteConfiguration> cfgClo)
- throws IgniteCheckedException {
- A.notNull(springCfgUrl, "springCfgUrl");
-
- boolean isLog4jUsed = U.gridClassLoader().getResource("org/apache/log4j/Appender.class") != null;
-
- IgniteBiTuple<Object, Object> t = null;
-
- if (isLog4jUsed) {
- try {
- t = U.addLog4jNoOpLogger();
- }
- catch (IgniteCheckedException ignore) {
- isLog4jUsed = false;
- }
- }
-
- Collection<Handler> savedHnds = null;
-
- if (!isLog4jUsed)
- savedHnds = U.addJavaNoOpLogger();
-
- IgniteBiTuple<Collection<IgniteConfiguration>, ? extends GridSpringResourceContext> cfgMap;
-
- try {
- cfgMap = loadConfigurations(springCfgUrl);
- }
- finally {
- if (isLog4jUsed && t != null)
- U.removeLog4jNoOpLogger(t);
-
- if (!isLog4jUsed)
- U.removeJavaNoOpLogger(savedHnds);
- }
-
- return startConfigurations(cfgMap, springCfgUrl, gridName, springCtx, cfgClo);
- }
-
- /**
- * Internal Spring-based start routine.
- *
- * @param springCfgStream Input stream containing Spring XML configuration. This cannot be {@code null}.
- * @param gridName Grid name that will override default.
- * @param springCtx Optional Spring application context.
- * @param cfgClo Optional closure to change configuration before it is used to start the grid.
- * @return Started grid.
- * @throws IgniteCheckedException If failed.
- */
- private static Ignite start(final InputStream springCfgStream, @Nullable String gridName,
- @Nullable GridSpringResourceContext springCtx,
- @Nullable IgniteClosure<IgniteConfiguration, IgniteConfiguration> cfgClo)
- throws IgniteCheckedException {
A.notNull(springCfgStream, "springCfgUrl");
boolean isLog4jUsed = U.gridClassLoader().getResource("org/apache/log4j/Appender.class") != null;
@@ -880,7 +830,7 @@ public class IgnitionEx {
U.removeJavaNoOpLogger(savedHnds);
}
- return startConfigurations(cfgMap, null, gridName, springCtx, cfgClo);
+ return startConfigurations(cfgMap, null, gridName, springCtx);
}
/**
@@ -890,7 +840,6 @@ public class IgnitionEx {
* @param springCfgUrl Spring XML configuration file URL.
* @param gridName Grid name that will override default.
* @param springCtx Optional Spring application context.
- * @param cfgClo Optional closure to change configuration before it is used to start the grid.
* @return Started grid.
* @throws IgniteCheckedException If failed.
*/
@@ -898,8 +847,7 @@ public class IgnitionEx {
IgniteBiTuple<Collection<IgniteConfiguration>, ? extends GridSpringResourceContext> cfgMap,
URL springCfgUrl,
@Nullable String gridName,
- @Nullable GridSpringResourceContext springCtx,
- @Nullable IgniteClosure<IgniteConfiguration, IgniteConfiguration> cfgClo)
+ @Nullable GridSpringResourceContext springCtx)
throws IgniteCheckedException {
List<IgniteNamedInstance> grids = new ArrayList<>(cfgMap.size());
@@ -910,12 +858,6 @@ public class IgnitionEx {
if (cfg.getGridName() == null && !F.isEmpty(gridName))
cfg.setGridName(gridName);
- if (cfgClo != null) {
- cfg = cfgClo.apply(cfg);
-
- assert cfg != null;
- }
-
// Use either user defined context or our one.
IgniteNamedInstance grid = start0(
new GridStartContext(cfg, springCfgUrl, springCtx == null ? cfgMap.get2() : springCtx));
@@ -1600,9 +1542,9 @@ public class IgnitionEx {
igfsExecSvc, restExecSvc,
new CA() {
@Override public void apply() {
- startLatch.countDown();
- }
- });
+ startLatch.countDown();
+ }
+ });
state = STARTED;
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/eca8ea57/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropBootstrap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropBootstrap.java b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropBootstrap.java
new file mode 100644
index 0000000..820bef9
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropBootstrap.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.ignite.internal.interop;
+
+import org.apache.ignite.configuration.*;
+
+/**
+ * Interop bootstrap. Responsible for starting Ignite node in interop mode.
+ */
+public interface InteropBootstrap {
+ /**
+ * Start Ignite node.
+ *
+ * @param cfg Configuration.
+ * @param envPtr Environment pointer.
+ * @return Ignite node.
+ */
+ public InteropProcessor start(IgniteConfiguration cfg, long envPtr);
+}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/eca8ea57/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropBootstrapFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropBootstrapFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropBootstrapFactory.java
new file mode 100644
index 0000000..b61ca89
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropBootstrapFactory.java
@@ -0,0 +1,39 @@
+/*
+ * 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.ignite.internal.interop;
+
+import java.io.*;
+
+/**
+ * Interop bootstrap factory.
+ */
+public interface InteropBootstrapFactory extends Serializable {
+ /**
+ * Get bootstrap factory ID.
+ *
+ * @return ID.
+ */
+ public int id();
+
+ /**
+ * Create bootstrap instance.
+ *
+ * @return Bootstrap instance.
+ */
+ public InteropBootstrap create();
+}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/eca8ea57/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropIgnition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropIgnition.java b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropIgnition.java
new file mode 100644
index 0000000..f245122
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropIgnition.java
@@ -0,0 +1,103 @@
+/*
+ * 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.ignite.internal.interop;
+
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.processors.resource.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
+import org.jetbrains.annotations.*;
+
+import java.net.*;
+import java.security.*;
+import java.util.*;
+
+/**
+ * Entry point for interop nodes.
+ */
+@SuppressWarnings("UnusedDeclaration")
+public class InteropIgnition {
+ /**
+ * Start Ignite node in interop mode.
+ *
+ * @param springCfgPath Spring configuration path.
+ * @param gridName Grid name.
+ * @param factoryId Factory ID.
+ * @param envPtr Environment pointer.
+ * @return Ignite instance.
+ */
+ public static InteropProcessor start(@Nullable String springCfgPath, @Nullable String gridName, int factoryId,
+ long envPtr) {
+ IgniteConfiguration cfg = configuration(springCfgPath);
+
+ if (gridName != null)
+ cfg.setGridName(gridName);
+
+ InteropBootstrap bootstrap = bootstrap(factoryId);
+
+ return bootstrap.start(cfg, envPtr);
+ }
+
+ private static IgniteConfiguration configuration(@Nullable String springCfgPath) {
+ try {
+ URL url = springCfgPath == null ? U.resolveIgniteUrl(IgnitionEx.DFLT_CFG) :
+ U.resolveSpringUrl(springCfgPath);
+
+ IgniteBiTuple<IgniteConfiguration, GridSpringResourceContext> t = IgnitionEx.loadConfiguration(url);
+
+ return t.get1();
+ }
+ catch (IgniteCheckedException e) {
+ throw new IgniteException("Failed to instantiate configuration from Spring XML: " + springCfgPath, e);
+ }
+ }
+
+ /**
+ * Create bootstrap for the given factory ID.
+ *
+ * @param factoryId Factory ID.
+ * @return Bootstrap.
+ */
+ private static InteropBootstrap bootstrap(final int factoryId) {
+ InteropBootstrapFactory factory = AccessController.doPrivileged(
+ new PrivilegedAction<InteropBootstrapFactory>() {
+ @Override public InteropBootstrapFactory run() {
+ for (InteropBootstrapFactory factory : ServiceLoader.load(InteropBootstrapFactory.class)) {
+ if (factory.id() == factoryId)
+ return factory;
+ }
+
+ return null;
+ }
+ });
+
+ if (factory == null)
+ throw new IgniteException("Interop factory is not found (did you put into the classpath?): " + factoryId);
+
+ return factory.create();
+ }
+
+ /**
+ * Private constructor.
+ */
+ private InteropIgnition() {
+ // No-op.
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/eca8ea57/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropProcessor.java
new file mode 100644
index 0000000..6c55296
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropProcessor.java
@@ -0,0 +1,25 @@
+/*
+ * 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.ignite.internal.interop;
+
+/**
+ * Interop processor.
+ */
+public interface InteropProcessor {
+ // No-op.
+}