use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class MessagingExample method startListening.
/**
* Start listening to messages on remote cluster nodes.
*
* @param msg Ignite messaging.
*/
private static void startListening(IgniteMessaging msg) {
// Add ordered message listener.
msg.remoteListen(EXAMPLE_TOPIC.ORDERED, new IgniteBiPredicate<UUID, String>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public boolean apply(UUID nodeId, String msg) {
System.out.println("Received ordered message [msg=" + msg + ", fromNodeId=" + nodeId + ']');
try {
ignite.message(ignite.cluster().forNodeId(nodeId)).send(EXAMPLE_TOPIC.ORDERED, msg);
} catch (IgniteException e) {
e.printStackTrace();
}
// Return true to continue listening.
return true;
}
});
// Add unordered message listener.
msg.remoteListen(EXAMPLE_TOPIC.UNORDERED, new IgniteBiPredicate<UUID, String>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public boolean apply(UUID nodeId, String msg) {
System.out.println("Received unordered message [msg=" + msg + ", fromNodeId=" + nodeId + ']');
try {
ignite.message(ignite.cluster().forNodeId(nodeId)).send(EXAMPLE_TOPIC.UNORDERED, msg);
} catch (IgniteException e) {
e.printStackTrace();
}
// Return true to continue listening.
return true;
}
});
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class IgfsSecondaryFileSystemInjectionSelfTest method testInjectPrimaryByField.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "UnusedDeclaration" })
public void testInjectPrimaryByField() throws Exception {
secondary = new TestBaseSecondaryFsMock() {
@FileSystemResource
private IgfsImpl igfs;
@LoggerResource
private IgniteLogger log;
@IgniteInstanceResource
private Ignite ig;
@Override
boolean checkInjection(Ignite ignite, IgniteFileSystem primary) {
return igfs == primary && log instanceof IgniteLogger && ig == ignite;
}
};
Ignite ig = startGrid(0);
IgniteFileSystem igfs = ig.fileSystem(IGFS_NAME);
assert secondary.checkInjection(ig, igfs);
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class IgfsSecondaryFileSystemInjectionSelfTest method testInjectPrimaryByMethods.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "UnusedDeclaration" })
public void testInjectPrimaryByMethods() throws Exception {
secondary = new TestBaseSecondaryFsMock() {
/**
* Ignite instance.
*/
private Ignite ig;
/**
* IGFS instance.
*/
private IgniteFileSystem igfs;
/**
* Logger injected flag
*/
private boolean logSet;
/**
* @param igfs Primary IGFS.
*/
@FileSystemResource
void setPrimaryIgfs(IgfsImpl igfs) {
this.igfs = igfs;
}
/**
* @param log Ignite logger.
*/
@LoggerResource
void setIgLogger(IgniteLogger log) {
logSet = log instanceof IgniteLogger;
}
/**
* @param ig Ignite instance.
*/
@IgniteInstanceResource
void setIgniteInst(Ignite ig) {
this.ig = ig;
}
@Override
boolean checkInjection(Ignite ignite, IgniteFileSystem primary) {
return ignite == ig && primary == igfs && logSet;
}
};
Ignite ig = startGrid(0);
IgniteFileSystem igfs = ig.fileSystem(IGFS_NAME);
assert secondary.checkInjection(ig, igfs);
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class GridCacheAbstractDataStructuresFailoverSelfTest method testAtomicSequenceInitialization.
/**
* @throws Exception If failed.
*/
public void testAtomicSequenceInitialization() throws Exception {
int threadCnt = 3;
final AtomicInteger idx = new AtomicInteger(gridCount());
IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new CA() {
@Override
public void apply() {
int id = idx.getAndIncrement();
try {
log.info("Start node: " + id);
startGrid(id);
Thread.sleep(1000);
} catch (Exception e) {
throw F.wrap(e);
} finally {
stopGrid(id);
info("Thread finished.");
}
}
}, threadCnt, "test-thread");
while (!fut.isDone()) {
grid(0).compute().call(new IgniteCallable<Object>() {
/**
*/
@IgniteInstanceResource
private Ignite g;
@Override
public Object call() throws Exception {
IgniteAtomicSequence seq = g.atomicSequence(STRUCTURE_NAME, 1, true);
assert seq != null;
for (int i = 0; i < 1000; i++) seq.getAndIncrement();
return null;
}
});
}
fut.get();
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class PlatformCacheEntryFilterImpl method setIgniteInstance.
/**
* @param ignite Ignite instance.
*/
@IgniteInstanceResource
public void setIgniteInstance(Ignite ignite) {
ctx = PlatformUtils.platformContext(ignite);
if (ptr != 0)
return;
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = ctx.writer(out);
writer.writeObject(pred);
out.synchronize();
ptr = ctx.gateway().cacheEntryFilterCreate(mem.pointer());
}
}
Aggregations