Repository: incubator-ignite Updated Branches: refs/heads/ignite-45 5f3c90b32 -> 0eb53a9d6
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c9df98f8/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/montecarlo/CreditRiskManager.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/montecarlo/CreditRiskManager.java b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/montecarlo/CreditRiskManager.java deleted file mode 100644 index 2ee8e23..0000000 --- a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/montecarlo/CreditRiskManager.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * 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.examples.java8.computegrid.montecarlo; - -import java.util.*; - -/** - * This class abstracts out the calculation of risk for a credit portfolio. - */ -@SuppressWarnings({"FloatingPointEquality"}) -public class CreditRiskManager { - /** - * Default randomizer with normal distribution. - * Note that since every JVM on the cluster will have its own random - * generator (independently initialized) the Monte-Carlo simulation - * will be slightly skewed when performed on the ignite cluster due to skewed - * normal distribution of the sub-jobs comparing to execution on the - * local node only with single random generator. Real-life applications - * may want to provide its own implementation of distributed random - * generator. - */ - private static Random rndGen = new Random(); - - /** - * Calculates credit risk for a given credit portfolio. This calculation uses - * Monte-Carlo Simulation to produce risk value. - * - * @param portfolio Credit portfolio. - * @param horizon Forecast horizon (in days). - * @param num Number of Monte-Carlo iterations. - * @param percentile Cutoff level. - * @return Credit risk value, i.e. the minimal amount that creditor has to - * have available to cover possible defaults. - */ - public double calculateCreditRiskMonteCarlo(Credit[] portfolio, int horizon, int num, double percentile) { - System.out.println(">>> Calculating credit risk for portfolio [size=" + portfolio.length + ", horizon=" + - horizon + ", percentile=" + percentile + ", iterations=" + num + "] <<<"); - - long start = System.currentTimeMillis(); - - double[] losses = calculateLosses(portfolio, horizon, num); - - Arrays.sort(losses); - - double[] lossProbs = new double[losses.length]; - - // Count variational numbers. - // Every next one either has the same value or previous one plus probability of loss. - for (int i = 0; i < losses.length; i++) - if (i == 0) - // First time it's just a probability of first value. - lossProbs[i] = getLossProbability(losses, 0); - else if (losses[i] != losses[i - 1]) - // Probability of this loss plus previous one. - lossProbs[i] = getLossProbability(losses, i) + lossProbs[i - 1]; - else - // The same loss the same probability. - lossProbs[i] = lossProbs[i - 1]; - - // Count percentile. - double crdRisk = 0; - - for (int i = 0; i < lossProbs.length; i++) - if (lossProbs[i] > percentile) { - crdRisk = losses[i - 1]; - - break; - } - - System.out.println(">>> Finished calculating portfolio risk [risk=" + crdRisk + - ", time=" + (System.currentTimeMillis() - start) + "ms]"); - - return crdRisk; - } - - /** - * Calculates losses for the given credit portfolio using Monte-Carlo Simulation. - * Simulates probability of default only. - * - * @param portfolio Credit portfolio. - * @param horizon Forecast horizon. - * @param num Number of Monte-Carlo iterations. - * @return Losses array simulated by Monte Carlo method. - */ - private double[] calculateLosses(Credit[] portfolio, int horizon, int num) { - double[] losses = new double[num]; - - // Count losses using Monte-Carlo method. We generate random probability of default, - // if it exceeds certain credit default value we count losses - otherwise count income. - for (int i = 0; i < num; i++) - for (Credit crd : portfolio) { - int remDays = Math.min(crd.getRemainingTerm(), horizon); - - if (rndGen.nextDouble() >= 1 - crd.getDefaultProbability(remDays)) - // (1 + 'r' * min(H, W) / 365) * S. - // Where W is a horizon, H is a remaining crediting term, 'r' is an annual credit rate, - // S is a remaining credit amount. - losses[i] += (1 + crd.getAnnualRate() * Math.min(horizon, crd.getRemainingTerm()) / 365) - * crd.getRemainingAmount(); - else - // - 'r' * min(H,W) / 365 * S - // Where W is a horizon, H is a remaining crediting term, 'r' is a annual credit rate, - // S is a remaining credit amount. - losses[i] -= crd.getAnnualRate() * Math.min(horizon, crd.getRemainingTerm()) / 365 * - crd.getRemainingAmount(); - } - - return losses; - } - - /** - * Calculates probability of certain loss in array of losses. - * - * @param losses Array of losses. - * @param i Index of certain loss in array. - * @return Probability of loss with given index. - */ - private double getLossProbability(double[] losses, int i) { - double cnt = 0; - double loss = losses[i]; - - for (double tmp : losses) - if (loss == tmp) - cnt++; - - return cnt / losses.length; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c9df98f8/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/montecarlo/package-info.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/montecarlo/package-info.java b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/montecarlo/package-info.java deleted file mode 100644 index 5c2069c..0000000 --- a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/montecarlo/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 description. --> - * Monte-Carlo simulation example. - */ -package org.apache.ignite.examples.java8.computegrid.montecarlo; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c9df98f8/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/package-info.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/package-info.java b/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/package-info.java new file mode 100644 index 0000000..2730f26 --- /dev/null +++ b/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/package-info.java @@ -0,0 +1,22 @@ +/* + * 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 description. --> + * Demonstrates data ignite cache usage. + */ +package org.apache.ignite.examples.java8.datagrid; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c9df98f8/examples/src/main/java8/org/apache/ignite/examples/java8/events/EventsExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/events/EventsExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/events/EventsExample.java new file mode 100644 index 0000000..d1c32a3 --- /dev/null +++ b/examples/src/main/java8/org/apache/ignite/examples/java8/events/EventsExample.java @@ -0,0 +1,132 @@ +/* + * 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.examples.java8.events; + +import org.apache.ignite.*; +import org.apache.ignite.compute.*; +import org.apache.ignite.events.*; +import org.apache.ignite.examples.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.resources.*; + +import java.util.*; + +import static org.apache.ignite.events.EventType.*; + +/** + * Demonstrates event consume API that allows to register event listeners on remote nodes. + * Note that ignite events are disabled by default and must be specifically enabled, + * just like in {@code examples/config/example-ignite.xml} file. + * <p> + * Remote nodes should always be started with configuration: {@code 'ignite.sh examples/config/example-ignite.xml'}. + * <p> + * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start + * node with {@code examples/config/example-ignite.xml} configuration. + */ +public class EventsExample { + /** + * Executes example. + * + * @param args Command line arguments, none required. + * @throws Exception If example execution failed. + */ + public static void main(String[] args) throws Exception { + try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { + System.out.println(); + System.out.println(">>> Events API example started."); + + // Listen to events happening on local node. + localListen(); + + // Listen to events happening on all cluster nodes. + remoteListen(); + + // Wait for a while while callback is notified about remaining puts. + Thread.sleep(1000); + } + } + + /** + * Listen to events that happen only on local node. + * + * @throws IgniteException If failed. + */ + private static void localListen() throws IgniteException { + System.out.println(); + System.out.println(">>> Local event listener example."); + + Ignite ignite = Ignition.ignite(); + + IgnitePredicate<TaskEvent> lsnr = evt -> { + System.out.println("Received task event [evt=" + evt.name() + ", taskName=" + evt.taskName() + ']'); + + return true; // Return true to continue listening. + }; + + // Register event listener for all local task execution events. + ignite.events().localListen(lsnr, EVTS_TASK_EXECUTION); + + // Generate task events. + ignite.compute().withName("example-event-task").run(() -> System.out.println("Executing sample job.")); + + // Unsubscribe local task event listener. + ignite.events().stopLocalListen(lsnr); + } + + /** + * Listen to events coming from all cluster nodes. + * + * @throws IgniteException If failed. + */ + private static void remoteListen() throws IgniteException { + System.out.println(); + System.out.println(">>> Remote event listener example."); + + // This optional local callback is called for each event notification + // that passed remote predicate listener. + IgniteBiPredicate<UUID, TaskEvent> locLsnr = (nodeId, evt) -> { + // Remote filter only accepts tasks whose name being with "good-task" prefix. + assert evt.taskName().startsWith("good-task"); + + System.out.println("Received task event [evt=" + evt.name() + ", taskName=" + evt.taskName()); + + return true; // Return true to continue listening. + }; + + // Remote filter which only accepts tasks whose name begins with "good-task" prefix. + IgnitePredicate<TaskEvent> rmtLsnr = evt -> evt.taskName().startsWith("good-task"); + + Ignite ignite = Ignition.ignite(); + + // Register event listeners on all nodes to listen for task events. + ignite.events().remoteListen(locLsnr, rmtLsnr, EVTS_TASK_EXECUTION); + + // Generate task events. + for (int i = 0; i < 10; i++) { + ignite.compute().withName(i < 5 ? "good-task-" + i : "bad-task-" + i).run(new IgniteRunnable() { + // Auto-inject task session. + @TaskSessionResource + private ComputeTaskSession ses; + + @Override public void run() { + System.out.println("Executing sample job for task: " + ses.getTaskName()); + } + }); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c9df98f8/examples/src/main/java8/org/apache/ignite/examples/java8/events/package-info.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/events/package-info.java b/examples/src/main/java8/org/apache/ignite/examples/java8/events/package-info.java new file mode 100644 index 0000000..f31a4c6 --- /dev/null +++ b/examples/src/main/java8/org/apache/ignite/examples/java8/events/package-info.java @@ -0,0 +1,22 @@ +/* + * 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 description. --> + * Demonstrates events management API. + */ +package org.apache.ignite.examples.java8.events; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c9df98f8/examples/src/main/java8/org/apache/ignite/examples/java8/messaging/MessagingPingPongExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/messaging/MessagingPingPongExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/messaging/MessagingPingPongExample.java new file mode 100644 index 0000000..8285956 --- /dev/null +++ b/examples/src/main/java8/org/apache/ignite/examples/java8/messaging/MessagingPingPongExample.java @@ -0,0 +1,111 @@ +/* + * 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.examples.java8.messaging; + +import org.apache.ignite.*; +import org.apache.ignite.cluster.*; +import org.apache.ignite.examples.*; + +import java.util.concurrent.*; + +/** + * Demonstrates simple message exchange between local and remote nodes. + * <p> + * To run this example you must have at least one remote node started. + * <p> + * Remote nodes should always be started with special configuration file which + * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}. + * <p> + * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start node + * with {@code examples/config/example-ignite.xml} configuration. + */ +public class MessagingPingPongExample { + /** + * Executes example. + * + * @param args Command line arguments, none required. + * @throws Exception If example execution failed. + */ + public static void main(String[] args) throws Exception { + // Game is played over the default ignite. + try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { + if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2)) + return; + + System.out.println(); + System.out.println(">>> Messaging ping-pong example started."); + + // Pick random remote node as a partner. + ClusterGroup nodeB = ignite.cluster().forRemotes().forRandom(); + + // Note that both nodeA and nodeB will always point to + // same nodes regardless of whether they were implicitly + // serialized and deserialized on another node as part of + // anonymous closure's state during its remote execution. + + // Set up remote player. + ignite.message(nodeB).remoteListen(null, (nodeId, rcvMsg) -> { + System.out.println("Received message [msg=" + rcvMsg + ", sender=" + nodeId + ']'); + + if ("PING".equals(rcvMsg)) { + ignite.message(ignite.cluster().forNodeId(nodeId)).send(null, "PONG"); + + return true; // Continue listening. + } + + return false; // Unsubscribe. + }); + + int MAX_PLAYS = 10; + + final CountDownLatch cnt = new CountDownLatch(MAX_PLAYS); + + // Set up local player. + ignite.message().localListen(null, (nodeId, rcvMsg) -> { + System.out.println("Received message [msg=" + rcvMsg + ", sender=" + nodeId + ']'); + + if (cnt.getCount() == 1) { + ignite.message(ignite.cluster().forNodeId(nodeId)).send(null, "STOP"); + + cnt.countDown(); + + return false; // Stop listening. + } + else if ("PONG".equals(rcvMsg)) + ignite.message(ignite.cluster().forNodeId(nodeId)).send(null, "PING"); + else + throw new IgniteException("Received unexpected message: " + rcvMsg); + + cnt.countDown(); + + return true; // Continue listening. + }); + + // Serve! + ignite.message(nodeB).send(null, "PING"); + + // Wait til the game is over. + try { + cnt.await(); + } + catch (InterruptedException e) { + System.err.println("Hm... let us finish the game!\n" + e); + } + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c9df98f8/examples/src/main/java8/org/apache/ignite/examples/java8/messaging/package-info.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/messaging/package-info.java b/examples/src/main/java8/org/apache/ignite/examples/java8/messaging/package-info.java new file mode 100644 index 0000000..0b03ea7 --- /dev/null +++ b/examples/src/main/java8/org/apache/ignite/examples/java8/messaging/package-info.java @@ -0,0 +1,22 @@ +/* + * 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 description. --> + * Demonstrates how to exchange messages between nodes. + */ +package org.apache.ignite.examples.java8.messaging; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c9df98f8/examples/src/main/java8/org/apache/ignite/examples/java8/misc/schedule/ComputeScheduleExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/misc/schedule/ComputeScheduleExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/misc/schedule/ComputeScheduleExample.java new file mode 100644 index 0000000..ac89c52 --- /dev/null +++ b/examples/src/main/java8/org/apache/ignite/examples/java8/misc/schedule/ComputeScheduleExample.java @@ -0,0 +1,64 @@ +/* + * 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.examples.java8.misc.schedule; + +import org.apache.ignite.*; +import org.apache.ignite.examples.*; +import org.apache.ignite.scheduler.*; + +/** + * Demonstrates a cron-based {@link Runnable} execution scheduling. + * Test runnable object broadcasts a phrase to all cluster nodes every minute + * three times with initial scheduling delay equal to five seconds. + * <p> + * Remote nodes should always be started with special configuration file which + * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}. + * <p> + * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start node + * with {@code examples/config/example-ignite.xml} configuration. + */ +public class ComputeScheduleExample { + /** + * Executes example. + * + * @param args Command line arguments, none required. + * @throws IgniteException If example execution failed. + */ + public static void main(String[] args) throws IgniteException { + try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { + System.out.println(); + System.out.println("Compute schedule example started."); + + // Schedule output message every minute. + SchedulerFuture<?> fut = ignite.scheduler().scheduleLocal(() -> + ignite.compute().broadcast(() -> { + System.out.println(); + System.out.println("Howdy! :) "); + }), + "{5, 3} * * * * *" // Cron expression. + ); + + while (!fut.isDone()) + System.out.println(">>> Invocation #: " + fut.get()); + + System.out.println(); + System.out.println(">>> Schedule future is done and has been unscheduled."); + System.out.println(">>> Check all nodes for hello message output."); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c9df98f8/examples/src/main/java8/org/apache/ignite/examples/java8/misc/schedule/package-info.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/misc/schedule/package-info.java b/examples/src/main/java8/org/apache/ignite/examples/java8/misc/schedule/package-info.java new file mode 100644 index 0000000..d90220f --- /dev/null +++ b/examples/src/main/java8/org/apache/ignite/examples/java8/misc/schedule/package-info.java @@ -0,0 +1,22 @@ +/* + * 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 description. --> + * Demonstrates usage of cron-based scheduler. + */ +package org.apache.ignite.examples.java8.misc.schedule; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c9df98f8/examples/src/main/java8/org/apache/ignite/examples/java8/package-info.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/package-info.java b/examples/src/main/java8/org/apache/ignite/examples/java8/package-info.java new file mode 100644 index 0000000..05fd206 --- /dev/null +++ b/examples/src/main/java8/org/apache/ignite/examples/java8/package-info.java @@ -0,0 +1,22 @@ +/* + * 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 description. --> + * Basic examples for ignite functionality. + */ +package org.apache.ignite.examples.java8; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c9df98f8/examples/src/main/java8/org/apache/ignite/examples/java8/streaming/package-info.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/streaming/package-info.java b/examples/src/main/java8/org/apache/ignite/examples/java8/streaming/package-info.java new file mode 100644 index 0000000..a29e8aa --- /dev/null +++ b/examples/src/main/java8/org/apache/ignite/examples/java8/streaming/package-info.java @@ -0,0 +1,22 @@ +/* + * 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 description. --> + * Demonstrates usage of data streamer. + */ +package org.apache.ignite.examples.java8.streaming; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c9df98f8/examples/src/test/java/org/apache/ignite/examples/BasicExamplesSelfTest.java ---------------------------------------------------------------------- diff --git a/examples/src/test/java/org/apache/ignite/examples/BasicExamplesSelfTest.java b/examples/src/test/java/org/apache/ignite/examples/BasicExamplesSelfTest.java index 11f8bc7..4c28b76 100644 --- a/examples/src/test/java/org/apache/ignite/examples/BasicExamplesSelfTest.java +++ b/examples/src/test/java/org/apache/ignite/examples/BasicExamplesSelfTest.java @@ -18,6 +18,7 @@ package org.apache.ignite.examples; import org.apache.ignite.examples.computegrid.*; +import org.apache.ignite.examples.datastructures.*; import org.apache.ignite.testframework.junits.common.*; /** @@ -49,7 +50,7 @@ public class BasicExamplesSelfTest extends GridAbstractExamplesTest { * @throws Exception If failed. */ public void testExecutorExample() throws Exception { - ComputeExecutorServiceExample.main(EMPTY_ARGS); + IgniteExecutorServiceExample.main(EMPTY_ARGS); } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c9df98f8/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java index 1adf754..cd76512 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java @@ -823,13 +823,6 @@ public class GridServiceProcessor extends GridProcessorAdapter { finally { // Suicide. exe.shutdownNow(); - - try { - ctx.resource().cleanup(cp); - } - catch (IgniteCheckedException e) { - log.error("Failed to clean up service (will ignore): " + svcCtx.name(), e); - } } } }); @@ -867,29 +860,37 @@ public class GridServiceProcessor extends GridProcessorAdapter { */ private void cancel(Iterable<ServiceContextImpl> ctxs, int cancelCnt) { for (Iterator<ServiceContextImpl> it = ctxs.iterator(); it.hasNext();) { - ServiceContextImpl ctx = it.next(); + ServiceContextImpl svcCtx = it.next(); // Flip cancelled flag. - ctx.setCancelled(true); + svcCtx.setCancelled(true); // Notify service about cancellation. try { - ctx.service().cancel(ctx); + svcCtx.service().cancel(svcCtx); } catch (Throwable e) { - log.error("Failed to cancel service (ignoring) [name=" + ctx.name() + - ", execId=" + ctx.executionId() + ']', e); + log.error("Failed to cancel service (ignoring) [name=" + svcCtx.name() + + ", execId=" + svcCtx.executionId() + ']', e); + } + finally { + try { + ctx.resource().cleanup(svcCtx.service()); + } + catch (IgniteCheckedException e) { + log.error("Failed to clean up service (will ignore): " + svcCtx.name(), e); + } } // Close out executor thread for the service. // This will cause the thread to be interrupted. - ctx.executor().shutdownNow(); + svcCtx.executor().shutdownNow(); it.remove(); if (log.isInfoEnabled()) - log.info("Cancelled service instance [name=" + ctx.name() + ", execId=" + - ctx.executionId() + ']'); + log.info("Cancelled service instance [name=" + svcCtx.name() + ", execId=" + + svcCtx.executionId() + ']'); if (--cancelCnt == 0) break;