use of org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction in project ignite by apache.
the class PlatformDotNetConfigurationClosure method prepare.
/**
* Prepare .Net size.
*
* @param igniteCfg Ignite configuration.
* @param interopCfg Interop configuration.
*/
@SuppressWarnings("ConstantConditions")
private void prepare(IgniteConfiguration igniteCfg, PlatformDotNetConfigurationEx interopCfg) {
cfg = igniteCfg;
try (PlatformMemory outMem = memMgr.allocate()) {
try (PlatformMemory inMem = memMgr.allocate()) {
PlatformOutputStream out = outMem.output();
GridBinaryMarshaller marshaller = PlatformUtils.marshaller();
BinaryRawWriterEx writer = marshaller.writer(out);
PlatformConfigurationUtils.writeDotNetConfiguration(writer, interopCfg.unwrap());
// Write .NET beans
List<PlatformDotNetLifecycleBean> beans = beans(igniteCfg);
writer.writeInt(beans.size());
for (PlatformDotNetLifecycleBean bean : beans) {
writer.writeString(bean.getTypeName());
writer.writeMap(bean.getProperties());
}
// Write .NET affinity funcs
List<PlatformDotNetAffinityFunction> affFuncs = affinityFunctions(igniteCfg);
writer.writeInt(affFuncs.size());
for (PlatformDotNetAffinityFunction func : affFuncs) {
writer.writeString(func.getTypeName());
writer.writeMap(func.getProperties());
}
out.synchronize();
gate.extensionCallbackInLongLongOutLong(PlatformUtils.OP_PREPARE_DOT_NET, outMem.pointer(), inMem.pointer());
processPrepareResult(marshaller.reader(inMem.input()));
}
}
}
use of org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction in project ignite by apache.
the class PlatformDotNetConfigurationClosure method processPrepareResult.
/**
* Process prepare result.
*
* @param in Input stream.
*/
private void processPrepareResult(BinaryReaderExImpl in) {
assert cfg != null;
PlatformConfigurationUtils.readIgniteConfiguration(in, cfg);
// Process beans
List<PlatformDotNetLifecycleBean> beans = beans(cfg);
List<PlatformLifecycleBean> newBeans = new ArrayList<>();
int len = in.readInt();
for (int i = 0; i < len; i++) {
if (i < beans.size())
// Existing bean.
beans.get(i).initialize(gate, in.readLong());
else
// This bean is defined in .Net.
newBeans.add(new PlatformLifecycleBean(gate, in.readLong()));
}
if (!newBeans.isEmpty()) {
LifecycleBean[] newBeans0 = newBeans.toArray(new LifecycleBean[newBeans.size()]);
// New beans were added. Let's append them to the tail of the rest configured lifecycle beans.
LifecycleBean[] oldBeans = cfg.getLifecycleBeans();
if (oldBeans == null)
cfg.setLifecycleBeans(newBeans0);
else {
LifecycleBean[] mergedBeans = new LifecycleBean[oldBeans.length + newBeans.size()];
System.arraycopy(oldBeans, 0, mergedBeans, 0, oldBeans.length);
System.arraycopy(newBeans0, 0, mergedBeans, oldBeans.length, newBeans0.length);
cfg.setLifecycleBeans(mergedBeans);
}
}
// Process affinity functions
List<PlatformDotNetAffinityFunction> affFuncs = affinityFunctions(cfg);
if (!affFuncs.isEmpty()) {
for (PlatformDotNetAffinityFunction aff : affFuncs) aff.init(PlatformConfigurationUtils.readAffinityFunction(in));
}
}
use of org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction in project ignite by apache.
the class PlatformDotNetConfigurationClosure method affinityFunctions.
/**
* Find .NET affinity functions in configuration.
*
* @param cfg Configuration.
* @return affinity functions.
*/
private static List<PlatformDotNetAffinityFunction> affinityFunctions(IgniteConfiguration cfg) {
List<PlatformDotNetAffinityFunction> res = new ArrayList<>();
CacheConfiguration[] cacheCfg = cfg.getCacheConfiguration();
if (cacheCfg != null) {
for (CacheConfiguration ccfg : cacheCfg) {
if (ccfg.getAffinity() instanceof PlatformDotNetAffinityFunction)
res.add((PlatformDotNetAffinityFunction) ccfg.getAffinity());
}
}
return res;
}
use of org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction in project ignite by apache.
the class PlatformConfigurationUtils method writeAffinityFunction.
/**
* Writes the affinity functions.
*
* @param out Stream.
* @param f Affinity.
*/
private static void writeAffinityFunction(BinaryRawWriter out, AffinityFunction f) {
if (f instanceof PlatformDotNetAffinityFunction)
f = ((PlatformDotNetAffinityFunction) f).getFunc();
if (f instanceof RendezvousAffinityFunction) {
out.writeByte((byte) 2);
RendezvousAffinityFunction f0 = (RendezvousAffinityFunction) f;
out.writeInt(f0.getPartitions());
out.writeBoolean(f0.isExcludeNeighbors());
// override flags
out.writeByte((byte) 0);
// user func
out.writeObject(null);
} else if (f instanceof PlatformAffinityFunction) {
PlatformAffinityFunction f0 = (PlatformAffinityFunction) f;
AffinityFunction baseFunc = f0.getBaseFunc();
if (baseFunc instanceof RendezvousAffinityFunction) {
out.writeByte((byte) 2);
out.writeInt(f0.partitions());
out.writeBoolean(((RendezvousAffinityFunction) baseFunc).isExcludeNeighbors());
out.writeByte(f0.getOverrideFlags());
out.writeObject(f0.getUserFunc());
} else {
out.writeByte((byte) 3);
out.writeInt(f0.partitions());
// exclude neighbors
out.writeBoolean(false);
out.writeByte(f0.getOverrideFlags());
out.writeObject(f0.getUserFunc());
}
} else {
out.writeByte((byte) 0);
}
}
Aggregations