use of org.apache.ignite.spi.eventstorage.NoopEventStorageSpi in project ignite by apache.
the class VisorTaskUtils method collectEvents.
/**
* Grabs local events and detects if events was lost since last poll.
*
* @param ignite Target grid.
* @param evtOrderKey Unique key to take last order key from node local map.
* @param evtThrottleCntrKey Unique key to take throttle count from node local map.
* @param evtTypes Event types to collect.
* @param evtMapper Closure to map grid events to Visor data transfer objects.
* @return Collections of node events
*/
public static List<VisorGridEvent> collectEvents(Ignite ignite, String evtOrderKey, String evtThrottleCntrKey, int[] evtTypes, IgniteClosure<Event, VisorGridEvent> evtMapper) {
assert ignite != null;
assert evtTypes != null && evtTypes.length > 0;
ConcurrentMap<String, Long> nl = ignite.cluster().nodeLocalMap();
final long lastOrder = getOrElse(nl, evtOrderKey, -1L);
final long throttle = getOrElse(nl, evtThrottleCntrKey, 0L);
// When we first time arrive onto a node to get its local events,
// we'll grab only last those events that not older than given period to make sure we are
// not grabbing GBs of data accidentally.
final long notOlderThan = System.currentTimeMillis() - EVENTS_COLLECT_TIME_WINDOW;
// Flag for detecting gaps between events.
final AtomicBoolean lastFound = new AtomicBoolean(lastOrder < 0);
IgnitePredicate<Event> p = new IgnitePredicate<Event>() {
/** */
private static final long serialVersionUID = 0L;
@Override
public boolean apply(Event e) {
// Detects that events were lost.
if (!lastFound.get() && (lastOrder == e.localOrder()))
lastFound.set(true);
// Retains events by lastOrder, period and type.
return e.localOrder() > lastOrder && e.timestamp() > notOlderThan;
}
};
Collection<Event> evts = ignite.configuration().getEventStorageSpi() instanceof NoopEventStorageSpi ? Collections.<Event>emptyList() : ignite.events().localQuery(p, evtTypes);
// Update latest order in node local, if not empty.
if (!evts.isEmpty()) {
Event maxEvt = Collections.max(evts, EVTS_ORDER_COMPARATOR);
nl.put(evtOrderKey, maxEvt.localOrder());
}
// Update throttle counter.
if (!lastFound.get())
nl.put(evtThrottleCntrKey, throttle == 0 ? EVENTS_LOST_THROTTLE : throttle - 1);
boolean lost = !lastFound.get() && throttle == 0;
List<VisorGridEvent> res = new ArrayList<>(evts.size() + (lost ? 1 : 0));
if (lost)
res.add(new VisorGridEventsLost(ignite.cluster().localNode().id()));
for (Event e : evts) {
VisorGridEvent visorEvt = evtMapper.apply(e);
if (visorEvt != null)
res.add(visorEvt);
}
return res;
}
use of org.apache.ignite.spi.eventstorage.NoopEventStorageSpi in project ignite by apache.
the class GridEventStorageManager method localEvents.
/**
* @param p Grid event predicate.
* @return Collection of grid events.
*/
@SuppressWarnings("unchecked")
public <T extends Event> Collection<T> localEvents(IgnitePredicate<T> p) throws IgniteCheckedException {
assert p != null;
if (getSpi() instanceof NoopEventStorageSpi) {
throw new IgniteCheckedException("Failed to query events because default no-op event storage SPI is used. " + "Consider configuring " + MemoryEventStorageSpi.class.getSimpleName() + " or another " + EventStorageSpi.class.getSimpleName() + " implementation via " + "IgniteConfiguration.setEventStorageSpi() configuration property.");
}
if (p instanceof PlatformEventFilterListener) {
PlatformEventFilterListener p0 = (PlatformEventFilterListener) p;
p0.initialize(ctx);
try {
return (Collection<T>) getSpi().localEvents(p0);
} finally {
p0.onClose();
}
} else
return getSpi().localEvents(p);
}
use of org.apache.ignite.spi.eventstorage.NoopEventStorageSpi in project ignite by apache.
the class GridEventStorageDefaultExceptionTest method getConfiguration.
/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(final String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
cfg.setEventStorageSpi(new NoopEventStorageSpi());
return cfg;
}
use of org.apache.ignite.spi.eventstorage.NoopEventStorageSpi in project ignite by apache.
the class PlatformConfigurationUtils method readIgniteConfiguration.
/**
* Reads Ignite configuration.
* @param in Reader.
* @param cfg Configuration.
*/
public static void readIgniteConfiguration(BinaryRawReaderEx in, IgniteConfiguration cfg) {
if (in.readBoolean())
cfg.setClientMode(in.readBoolean());
int[] eventTypes = in.readIntArray();
if (eventTypes != null)
cfg.setIncludeEventTypes(eventTypes);
if (in.readBoolean())
cfg.setMetricsExpireTime(in.readLong());
if (in.readBoolean())
cfg.setMetricsHistorySize(in.readInt());
if (in.readBoolean())
cfg.setMetricsLogFrequency(in.readLong());
if (in.readBoolean())
cfg.setMetricsUpdateFrequency(in.readLong());
if (in.readBoolean())
cfg.setNetworkSendRetryCount(in.readInt());
if (in.readBoolean())
cfg.setNetworkSendRetryDelay(in.readLong());
if (in.readBoolean())
cfg.setNetworkTimeout(in.readLong());
String workDir = in.readString();
if (workDir != null)
cfg.setWorkDirectory(workDir);
String localHost = in.readString();
if (localHost != null)
cfg.setLocalHost(localHost);
if (in.readBoolean())
cfg.setDaemon(in.readBoolean());
if (in.readBoolean())
cfg.setLateAffinityAssignment(in.readBoolean());
if (in.readBoolean())
cfg.setFailureDetectionTimeout(in.readLong());
if (in.readBoolean())
cfg.setClientFailureDetectionTimeout(in.readLong());
readCacheConfigurations(in, cfg);
readDiscoveryConfiguration(in, cfg);
if (in.readBoolean()) {
TcpCommunicationSpi comm = new TcpCommunicationSpi();
comm.setAckSendThreshold(in.readInt());
comm.setConnectTimeout(in.readLong());
comm.setDirectBuffer(in.readBoolean());
comm.setDirectSendBuffer(in.readBoolean());
comm.setIdleConnectionTimeout(in.readLong());
comm.setLocalAddress(in.readString());
comm.setLocalPort(in.readInt());
comm.setLocalPortRange(in.readInt());
comm.setMaxConnectTimeout(in.readLong());
comm.setMessageQueueLimit(in.readInt());
comm.setReconnectCount(in.readInt());
comm.setSelectorsCount(in.readInt());
comm.setSlowClientQueueLimit(in.readInt());
comm.setSocketReceiveBuffer(in.readInt());
comm.setSocketSendBuffer(in.readInt());
comm.setTcpNoDelay(in.readBoolean());
comm.setUnacknowledgedMessagesBufferSize(in.readInt());
cfg.setCommunicationSpi(comm);
}
if (in.readBoolean()) {
// binary config is present
if (cfg.getBinaryConfiguration() == null)
cfg.setBinaryConfiguration(new BinaryConfiguration());
if (// compact footer is set
in.readBoolean())
cfg.getBinaryConfiguration().setCompactFooter(in.readBoolean());
if (in.readBoolean()) {
// Simple name mapper.
cfg.getBinaryConfiguration().setNameMapper(new BinaryBasicNameMapper(true));
}
}
int attrCnt = in.readInt();
if (attrCnt > 0) {
Map<String, Object> attrs = new HashMap<>(attrCnt);
for (int i = 0; i < attrCnt; i++) attrs.put(in.readString(), in.readObject());
cfg.setUserAttributes(attrs);
}
if (in.readBoolean()) {
AtomicConfiguration atomic = new AtomicConfiguration();
atomic.setAtomicSequenceReserveSize(in.readInt());
atomic.setBackups(in.readInt());
atomic.setCacheMode(CacheMode.fromOrdinal(in.readInt()));
cfg.setAtomicConfiguration(atomic);
}
if (in.readBoolean()) {
TransactionConfiguration tx = new TransactionConfiguration();
tx.setPessimisticTxLogSize(in.readInt());
tx.setDefaultTxConcurrency(TransactionConcurrency.fromOrdinal(in.readInt()));
tx.setDefaultTxIsolation(TransactionIsolation.fromOrdinal(in.readInt()));
tx.setDefaultTxTimeout(in.readLong());
tx.setPessimisticTxLogLinger(in.readInt());
cfg.setTransactionConfiguration(tx);
}
switch(in.readByte()) {
case 1:
cfg.setEventStorageSpi(new NoopEventStorageSpi());
break;
case 2:
cfg.setEventStorageSpi(new MemoryEventStorageSpi().setExpireCount(in.readLong()).setExpireAgeMs(in.readLong()));
break;
}
if (in.readBoolean())
cfg.setMemoryConfiguration(readMemoryConfiguration(in));
readPluginConfiguration(cfg, in);
}
use of org.apache.ignite.spi.eventstorage.NoopEventStorageSpi in project ignite by apache.
the class PlatformConfigurationUtils method writeIgniteConfiguration.
/**
* Writes Ignite configuration.
*
* @param w Writer.
* @param cfg Configuration.
*/
public static void writeIgniteConfiguration(BinaryRawWriter w, IgniteConfiguration cfg) {
assert w != null;
assert cfg != null;
w.writeBoolean(true);
w.writeBoolean(cfg.isClientMode());
w.writeIntArray(cfg.getIncludeEventTypes());
w.writeBoolean(true);
w.writeLong(cfg.getMetricsExpireTime());
w.writeBoolean(true);
w.writeInt(cfg.getMetricsHistorySize());
w.writeBoolean(true);
w.writeLong(cfg.getMetricsLogFrequency());
w.writeBoolean(true);
w.writeLong(cfg.getMetricsUpdateFrequency());
w.writeBoolean(true);
w.writeInt(cfg.getNetworkSendRetryCount());
w.writeBoolean(true);
w.writeLong(cfg.getNetworkSendRetryDelay());
w.writeBoolean(true);
w.writeLong(cfg.getNetworkTimeout());
w.writeString(cfg.getWorkDirectory());
w.writeString(cfg.getLocalHost());
w.writeBoolean(true);
w.writeBoolean(cfg.isDaemon());
w.writeBoolean(true);
w.writeBoolean(cfg.isLateAffinityAssignment());
w.writeBoolean(true);
w.writeLong(cfg.getFailureDetectionTimeout());
w.writeBoolean(true);
w.writeLong(cfg.getClientFailureDetectionTimeout());
CacheConfiguration[] cacheCfg = cfg.getCacheConfiguration();
if (cacheCfg != null) {
w.writeInt(cacheCfg.length);
for (CacheConfiguration ccfg : cacheCfg) writeCacheConfiguration(w, ccfg);
} else
w.writeInt(0);
writeDiscoveryConfiguration(w, cfg.getDiscoverySpi());
CommunicationSpi comm = cfg.getCommunicationSpi();
if (comm instanceof TcpCommunicationSpi) {
w.writeBoolean(true);
TcpCommunicationSpi tcp = (TcpCommunicationSpi) comm;
w.writeInt(tcp.getAckSendThreshold());
w.writeLong(tcp.getConnectTimeout());
w.writeBoolean(tcp.isDirectBuffer());
w.writeBoolean(tcp.isDirectSendBuffer());
w.writeLong(tcp.getIdleConnectionTimeout());
w.writeString(tcp.getLocalAddress());
w.writeInt(tcp.getLocalPort());
w.writeInt(tcp.getLocalPortRange());
w.writeLong(tcp.getMaxConnectTimeout());
w.writeInt(tcp.getMessageQueueLimit());
w.writeInt(tcp.getReconnectCount());
w.writeInt(tcp.getSelectorsCount());
w.writeInt(tcp.getSlowClientQueueLimit());
w.writeInt(tcp.getSocketReceiveBuffer());
w.writeInt(tcp.getSocketSendBuffer());
w.writeBoolean(tcp.isTcpNoDelay());
w.writeInt(tcp.getUnacknowledgedMessagesBufferSize());
} else
w.writeBoolean(false);
BinaryConfiguration bc = cfg.getBinaryConfiguration();
if (bc != null) {
// binary config exists
w.writeBoolean(true);
// compact footer is set
w.writeBoolean(true);
w.writeBoolean(bc.isCompactFooter());
w.writeBoolean(bc.getNameMapper() instanceof BinaryBasicNameMapper && ((BinaryBasicNameMapper) (bc.getNameMapper())).isSimpleName());
} else
w.writeBoolean(false);
Map<String, ?> attrs = cfg.getUserAttributes();
if (attrs != null) {
w.writeInt(attrs.size());
for (Map.Entry<String, ?> e : attrs.entrySet()) {
w.writeString(e.getKey());
w.writeObject(e.getValue());
}
} else
w.writeInt(0);
AtomicConfiguration atomic = cfg.getAtomicConfiguration();
if (atomic != null) {
w.writeBoolean(true);
w.writeInt(atomic.getAtomicSequenceReserveSize());
w.writeInt(atomic.getBackups());
writeEnumInt(w, atomic.getCacheMode(), AtomicConfiguration.DFLT_CACHE_MODE);
} else
w.writeBoolean(false);
TransactionConfiguration tx = cfg.getTransactionConfiguration();
if (tx != null) {
w.writeBoolean(true);
w.writeInt(tx.getPessimisticTxLogSize());
writeEnumInt(w, tx.getDefaultTxConcurrency(), TransactionConfiguration.DFLT_TX_CONCURRENCY);
writeEnumInt(w, tx.getDefaultTxIsolation(), TransactionConfiguration.DFLT_TX_ISOLATION);
w.writeLong(tx.getDefaultTxTimeout());
w.writeInt(tx.getPessimisticTxLogLinger());
} else
w.writeBoolean(false);
EventStorageSpi evtStorageSpi = cfg.getEventStorageSpi();
if (evtStorageSpi == null)
w.writeByte((byte) 0);
else if (evtStorageSpi instanceof NoopEventStorageSpi)
w.writeByte((byte) 1);
else if (evtStorageSpi instanceof MemoryEventStorageSpi) {
w.writeByte((byte) 2);
w.writeLong(((MemoryEventStorageSpi) evtStorageSpi).getExpireCount());
w.writeLong(((MemoryEventStorageSpi) evtStorageSpi).getExpireAgeMs());
}
writeMemoryConfiguration(w, cfg.getMemoryConfiguration());
w.writeString(cfg.getIgniteHome());
w.writeLong(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getInit());
w.writeLong(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax());
}
Aggregations