Search in sources :

Example 1 with PlatformDotNetAffinityFunction

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()));
        }
    }
}
Also used : GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) PlatformDotNetAffinityFunction(org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction) PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory) PlatformDotNetLifecycleBean(org.apache.ignite.platform.dotnet.PlatformDotNetLifecycleBean)

Example 2 with PlatformDotNetAffinityFunction

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));
    }
}
Also used : PlatformLifecycleBean(org.apache.ignite.internal.processors.platform.lifecycle.PlatformLifecycleBean) ArrayList(java.util.ArrayList) PlatformDotNetLifecycleBean(org.apache.ignite.platform.dotnet.PlatformDotNetLifecycleBean) LifecycleBean(org.apache.ignite.lifecycle.LifecycleBean) PlatformLifecycleBean(org.apache.ignite.internal.processors.platform.lifecycle.PlatformLifecycleBean) PlatformDotNetAffinityFunction(org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction) PlatformDotNetLifecycleBean(org.apache.ignite.platform.dotnet.PlatformDotNetLifecycleBean)

Example 3 with PlatformDotNetAffinityFunction

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;
}
Also used : ArrayList(java.util.ArrayList) PlatformDotNetAffinityFunction(org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 4 with PlatformDotNetAffinityFunction

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);
    }
}
Also used : PlatformAffinityFunction(org.apache.ignite.internal.processors.platform.cache.affinity.PlatformAffinityFunction) PlatformDotNetAffinityFunction(org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) PlatformAffinityFunction(org.apache.ignite.internal.processors.platform.cache.affinity.PlatformAffinityFunction) PlatformDotNetAffinityFunction(org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction)

Aggregations

PlatformDotNetAffinityFunction (org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction)4 ArrayList (java.util.ArrayList)2 PlatformDotNetLifecycleBean (org.apache.ignite.platform.dotnet.PlatformDotNetLifecycleBean)2 AffinityFunction (org.apache.ignite.cache.affinity.AffinityFunction)1 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)1 GridBinaryMarshaller (org.apache.ignite.internal.binary.GridBinaryMarshaller)1 PlatformAffinityFunction (org.apache.ignite.internal.processors.platform.cache.affinity.PlatformAffinityFunction)1 PlatformLifecycleBean (org.apache.ignite.internal.processors.platform.lifecycle.PlatformLifecycleBean)1 PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)1 PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)1 LifecycleBean (org.apache.ignite.lifecycle.LifecycleBean)1