Skip to content

Commit

Permalink
# ignite-106 review
Browse files Browse the repository at this point in the history
  • Loading branch information
sboikov committed Feb 3, 2015
1 parent 0f7b123 commit cb4a2f5
Show file tree
Hide file tree
Showing 34 changed files with 64 additions and 84 deletions.
2 changes: 1 addition & 1 deletion examples/config/filesystem/example-ggfs.xml
Expand Up @@ -53,7 +53,7 @@
Configuration below demonstrates how to setup a GGFS node with file data.
-->
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<!-- Set to true to enable ignite-aware class loading for examples, default is false. -->
<!-- Set to true to enable cluster-aware class loading for examples, default is false. -->
<property name="peerClassLoadingEnabled" value="true"/>

<property name="marshaller">
Expand Down
Expand Up @@ -57,9 +57,9 @@ public static void main(String[] args) throws Exception {
* Print 'Hello' message on all nodes.
*
* @param ignite Ignite instance.
* @throws IgniteCheckedException If failed.
* @throws IgniteException If failed.
*/
private static void hello(Ignite ignite) throws IgniteCheckedException {
private static void hello(Ignite ignite) throws IgniteException {
// Print out hello message on all nodes.
ignite.compute().broadcast(
new IgniteRunnable() {
Expand All @@ -78,9 +78,9 @@ private static void hello(Ignite ignite) throws IgniteCheckedException {
* Gather system info from all nodes and print it out.
*
* @param ignite Ignite instance.
* @throws IgniteCheckedException if failed.
* @throws IgniteException if failed.
*/
private static void gatherSystemInfo(Ignite ignite) throws IgniteCheckedException {
private static void gatherSystemInfo(Ignite ignite) throws IgniteException {
// Gather system info from all nodes.
Collection<String> res = ignite.compute().broadcast(
new IgniteCallable<String>() {
Expand Down
Expand Up @@ -41,9 +41,9 @@ public class ComputeCallableExample {
* Executes example.
*
* @param args Command line arguments, none required.
* @throws IgniteCheckedException If example execution failed.
* @throws Exception If example execution failed.
*/
public static void main(String[] args) throws IgniteCheckedException {
public static void main(String[] args) throws Exception {
try (Ignite ignite = Ignition.start("examples/config/example-compute.xml")) {
System.out.println();
System.out.println(">>> Compute callable example started.");
Expand All @@ -55,7 +55,7 @@ public static void main(String[] args) throws IgniteCheckedException {
calls.add(new IgniteCallable<Integer>() {
@Override public Integer call() throws Exception {
System.out.println();
System.out.println(">>> Printing '" + word + "' on this node from igntie job.");
System.out.println(">>> Printing '" + word + "' on this node from ignite job.");

return word.length();
}
Expand Down
Expand Up @@ -40,9 +40,9 @@ public class ComputeClosureExample {
* Executes example.
*
* @param args Command line arguments, none required.
* @throws IgniteCheckedException If example execution failed.
* @throws Exception If example execution failed.
*/
public static void main(String[] args) throws IgniteCheckedException {
public static void main(String[] args) throws Exception {
try (Ignite ignite = Ignition.start("examples/config/example-compute.xml")) {
System.out.println();
System.out.println(">>> Compute closure example started.");
Expand All @@ -52,7 +52,7 @@ public static void main(String[] args) throws IgniteCheckedException {
new IgniteClosure<String, Integer>() {
@Override public Integer apply(String word) {
System.out.println();
System.out.println(">>> Printing '" + word + "' on this node from igntie job.");
System.out.println(">>> Printing '" + word + "' on this node from ignite job.");

// Return number of letters in the word.
return word.length();
Expand Down
Expand Up @@ -33,7 +33,7 @@
* initial {@link org.apache.ignite.compute.ComputeTask#map(List, Object)} method completes.
* <p>
* String "Hello Continuous Mapper" is passed as an argument for execution
* of {@link org.apache.ignite.examples.compute.ComputeContinuousMapperExample.ContinuousMapperTask}. As an outcome, participating
* of {@link ContinuousMapperTask}. As an outcome, participating
* nodes will print out a single word from the passed in string and return
* number of characters in that word. However, to demonstrate continuous
* mapping, next word will be mapped to a node only after the result from
Expand Down Expand Up @@ -136,7 +136,7 @@ private void sendWord() {
String word = argument(0);

System.out.println();
System.out.println(">>> Printing '" + word + "' from igntie job at time: " + new Date());
System.out.println(">>> Printing '" + word + "' from ignite job at time: " + new Date());

int cnt = word.length();

Expand Down
Expand Up @@ -24,7 +24,7 @@
import java.util.concurrent.*;

/**
* Simple example to demonstrate usage of ignite-enabled executor service provided by Ignite.
* Simple example to demonstrate usage of distributed executor service provided by Ignite.
* <p>
* Remote nodes should always be started with special configuration file which
* enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-compute.xml'}.
Expand Down Expand Up @@ -54,7 +54,7 @@ public static void main(String[] args) throws Exception {
exec.submit(new IgniteRunnable() {
@Override public void run() {
System.out.println();
System.out.println(">>> Printing '" + word + "' on this node from igntie job.");
System.out.println(">>> Printing '" + word + "' on this node from ignite job.");
}
});
}
Expand Down
Expand Up @@ -76,16 +76,16 @@ public static void main(String[] args) throws Exception {
* Print 'Hello' message on remote nodes.
*
* @param ignite Ignite.
* @param prj Projection.
* @throws IgniteCheckedException If failed.
* @param grp Cluster group.
* @throws IgniteException If failed.
*/
private static void sayHello(Ignite ignite, final ClusterGroup prj) throws IgniteCheckedException {
private static void sayHello(Ignite ignite, final ClusterGroup grp) throws IgniteException {
// Print out hello message on all projection nodes.
ignite.compute(prj).broadcast(
ignite.compute(grp).broadcast(
new IgniteRunnable() {
@Override public void run() {
// Print ID of remote node on remote node.
System.out.println(">>> Hello Node: " + prj.ignite().cluster().localNode().id());
System.out.println(">>> Hello Node: " + grp.ignite().cluster().localNode().id());
}
}
);
Expand Down
Expand Up @@ -52,7 +52,7 @@ public static void main(String[] args) throws IgniteCheckedException {
new IgniteClosure<String, Integer>() {
@Override public Integer apply(String word) {
System.out.println();
System.out.println(">>> Printing '" + word + "' on this node from igntie job.");
System.out.println(">>> Printing '" + word + "' on this node from ignite job.");

// Return number of letters in the word.
return word.length();
Expand Down
Expand Up @@ -19,7 +19,6 @@

import org.apache.ignite.*;
import org.apache.ignite.examples.*;
import org.apache.ignite.internal.*;
import org.apache.ignite.lang.*;

import java.util.*;
Expand Down Expand Up @@ -56,7 +55,7 @@ public static void main(String[] args) throws IgniteCheckedException {
compute.run(new IgniteRunnable() {
@Override public void run() {
System.out.println();
System.out.println(">>> Printing '" + word + "' on this node from igntie job.");
System.out.println(">>> Printing '" + word + "' on this node from ignite job.");
}
});

Expand Down
Expand Up @@ -89,7 +89,7 @@ private static class CharacterCountTask extends ComputeTaskAdapter<String, Integ
map.put(new ComputeJobAdapter() {
@Nullable @Override public Object execute() {
System.out.println();
System.out.println(">>> Printing '" + word + "' on this node from igntie job.");
System.out.println(">>> Printing '" + word + "' on this node from ignite job.");

// Return number of letters in the word.
return word.length();
Expand Down
Expand Up @@ -78,7 +78,7 @@ private static class CharacterCountTask extends ComputeTaskSplitAdapter<String,
jobs.add(new ComputeJobAdapter() {
@Nullable @Override public Object execute() {
System.out.println();
System.out.println(">>> Printing '" + word + "' on this node from igntie job.");
System.out.println(">>> Printing '" + word + "' on this node from ignite job.");

// Return number of letters in the word.
return word.length();
Expand Down
Expand Up @@ -22,7 +22,6 @@
import org.apache.ignite.examples.*;
import org.apache.ignite.lang.*;
import org.apache.ignite.resources.*;
import org.apache.ignite.internal.util.lang.*;

import java.util.*;

Expand All @@ -39,9 +38,9 @@ public class ComputeFailoverExample {
* Executes example.
*
* @param args Command line arguments, none required.
* @throws IgniteCheckedException If example execution failed.
* @throws Exception If example execution failed.
*/
public static void main(String[] args) throws IgniteCheckedException {
public static void main(String[] args) throws Exception {
try (Ignite ignite = Ignition.start(ComputeFailoverNodeStartup.configuration())) {
if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2))
return;
Expand Down
Expand Up @@ -39,16 +39,6 @@ public class CreditRiskManager {
/**
* Calculates credit risk for a given credit portfolio. This calculation uses
* Monte-Carlo Simulation to produce risk value.
* <p>
* Note that this class generally represents a business logic and the entire
* grid enabling occurs in one line of annotation added to this method:
* <pre name="code" class="java">
* ...
* &#64;Gridify(taskClass = GridCreditRiskGridTask.class)
* ...
* </pre>
* Note also that this annotation could have been added externally via XML
* file leaving this file completely untouched - yet still fully grid enabled.
*
* @param portfolio Credit portfolio.
* @param horizon Forecast horizon (in days).
Expand Down
Expand Up @@ -18,7 +18,6 @@
package org.apache.ignite.examples.datagrid;

import org.apache.ignite.*;
import org.apache.ignite.cache.*;
import org.apache.ignite.cluster.*;
import org.apache.ignite.lang.*;

Expand Down Expand Up @@ -118,8 +117,7 @@ private static void visitUsingMapKeysToNodes() {
if (node != null) {
// Bring computations to the nodes where the data resides (i.e. collocation).
ignite.compute(ignite.cluster().forNode(node)).run(new IgniteRunnable() {
@Override
public void run() {
@Override public void run() {
IgniteCache<Integer, String> cache = ignite.jcache(CACHE_NAME);

// Peek is a local memory lookup, however, value should never be 'null'
Expand Down
Expand Up @@ -18,8 +18,6 @@
package org.apache.ignite.examples.datagrid;

import org.apache.ignite.*;
import org.apache.ignite.cache.*;
import org.apache.ignite.lang.*;

import javax.cache.processor.*;
import java.util.concurrent.*;
Expand Down
Expand Up @@ -18,7 +18,6 @@
package org.apache.ignite.examples.datagrid;

import org.apache.ignite.*;
import org.apache.ignite.cache.*;
import org.apache.ignite.events.*;
import org.apache.ignite.lang.*;

Expand Down
Expand Up @@ -67,10 +67,10 @@ public static void main(String[] args) throws Exception {
// Clean up caches on all nodes before run.
ignite.jcache(CACHE_NAME).clear();

ClusterGroup prj = ignite.cluster().forCache(CACHE_NAME);
ClusterGroup grp = ignite.cluster().forCache(CACHE_NAME);

if (prj.nodes().isEmpty()) {
System.out.println("Grid does not have cache configured: " + CACHE_NAME);
if (grp.nodes().isEmpty()) {
System.out.println("Ignite does not have cache configured: " + CACHE_NAME);

return;
}
Expand Down
Expand Up @@ -90,9 +90,11 @@ private static void deposit(int acctId, double amount) throws IgniteCheckedExcep
IgniteCache<Integer, Account> cache = Ignition.ignite().jcache(CACHE_NAME);

try (IgniteTx tx = Ignition.ignite().transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
assert cache.get(acctId) != null;
Account acct0 = cache.get(acctId);

Account acct = new Account(cache.get(acctId).id, cache.get(acctId).balance);
assert acct0 != null;

Account acct = new Account(acct0.id, acct0.balance);

// Deposit into account.
acct.update(amount);
Expand All @@ -110,7 +112,7 @@ private static void deposit(int acctId, double amount) throws IgniteCheckedExcep
/**
* Account.
*/
private static class Account implements Serializable, Cloneable {
private static class Account implements Serializable {
/** Account ID. */
private int id;

Expand All @@ -135,11 +137,6 @@ void update(double amount) {
balance += amount;
}

/** {@inheritDoc} */
@Override protected Object clone() throws CloneNotSupportedException {
return super.clone();
}

/** {@inheritDoc} */
@Override public String toString() {
return "Account [id=" + id + ", balance=$" + balance + ']';
Expand Down
Expand Up @@ -63,8 +63,7 @@ public static void main(String[] args) throws IgniteCheckedException {
// Try increment atomic long from all cluster nodes.
// Note that this node is also part of the cluster.
ignite.compute(ignite.cluster().forCache(CACHE_NAME)).call(new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
@Override public Object call() throws Exception {
for (int i = 0; i < RETRIES; i++)
System.out.println("AtomicLong value has been incremented: " + atomicLong.incrementAndGet());

Expand Down
Expand Up @@ -63,7 +63,7 @@ public static void main(String[] args) throws IgniteCheckedException {
// Make closure for checking atomic reference value on cluster.
Runnable c = new ReferenceClosure(CACHE_NAME, refName);

// Check atomic reference on all clsuter nodes.
// Check atomic reference on all cluster nodes.
ignite.compute().run(c);

// Make new value of atomic reference.
Expand Down
Expand Up @@ -59,7 +59,9 @@ public static void main(String[] args) throws Exception {

System.out.println("Read value: " + val);

cache.put(id, person(id, "Isaac", "Newton"));
val = cache.getAndPut(id, person(id, "Isaac", "Newton"));

System.out.println("Overwrote old value: " + val);

val = cache.get(id);

Expand Down
Expand Up @@ -60,8 +60,7 @@ public static void main(String[] args) throws Exception {

// Start loading cache on all caching nodes.
ignite.compute(ignite.cluster().forCache(null)).broadcast(new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
@Override public Object call() throws Exception {
// Load cache from persistent store.
cache.loadCache(null, 0, ENTRY_COUNT);

Expand Down
Expand Up @@ -32,7 +32,7 @@
* Dummy cache store implementation.
*/
public class CacheDummyPersonStore extends CacheStoreAdapter<Long, Person> {
/** Auto-inject igntie instance. */
/** Auto-inject ignite instance. */
@IgniteInstanceResource
private Ignite ignite;

Expand Down
Expand Up @@ -97,9 +97,9 @@ private static void localListen() throws Exception {
/**
* Listen to events coming from all cluster nodes.
*
* @throws IgniteCheckedException If failed.
* @throws IgniteException If failed.
*/
private static void remoteListen() throws IgniteCheckedException {
private static void remoteListen() throws IgniteException {
System.out.println();
System.out.println(">>> Remote event listener example.");

Expand Down
Expand Up @@ -105,9 +105,9 @@ public static void main(String[] args) throws Exception {
*
* @param fs GGFS.
* @param path File or directory path.
* @throws IgniteCheckedException In case of error.
* @throws IgniteException In case of error.
*/
private static void delete(IgniteFs fs, IgniteFsPath path) throws IgniteCheckedException {
private static void delete(IgniteFs fs, IgniteFsPath path) throws IgniteException {
assert fs != null;
assert path != null;

Expand Down
Expand Up @@ -33,9 +33,9 @@ public class GgfsNodeStartup {
* Start up an empty node with specified cache configuration.
*
* @param args Command line arguments, none required.
* @throws IgniteCheckedException If example execution failed.
* @throws IgniteException If example execution failed.
*/
public static void main(String[] args) throws IgniteCheckedException {
public static void main(String[] args) throws IgniteException {
Ignition.start("examples/config/filesystem/example-ggfs.xml");
}
}
Expand Up @@ -43,9 +43,9 @@ public class MessagingPingPongExample {
* Executes example.
*
* @param args Command line arguments, none required.
* @throws IgniteCheckedException If example execution failed.
* @throws Exception If example execution failed.
*/
public static void main(String[] args) throws IgniteCheckedException {
public static void main(String[] args) throws Exception {
// Game is played over the default ignite.
try (Ignite ignite = Ignition.start("examples/config/example-compute.xml")) {
if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2))
Expand Down

0 comments on commit cb4a2f5

Please sign in to comment.