Search in sources :

Example 31 with BinaryMarshaller

use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.

the class HibernateL2CacheMultiJvmTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    if (!getTestIgniteInstanceName(0).equals(igniteInstanceName))
        cfg.setClientMode(true);
    CacheConfiguration ccfg = new CacheConfiguration();
    ccfg.setName(CACHE_NAME);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    cfg.setCacheConfiguration(ccfg);
    cfg.setMarshaller(new BinaryMarshaller());
    cfg.setPeerClassLoadingEnabled(false);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 32 with BinaryMarshaller

use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.

the class GridComputationBinarylizableClosuresSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setMarshaller(new BinaryMarshaller());
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller)

Example 33 with BinaryMarshaller

use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.

the class PlatformUtils method marshaller.

/**
 * Create binary marshaller.
 *
 * @return Marshaller.
 */
@SuppressWarnings("deprecation")
public static GridBinaryMarshaller marshaller() {
    BinaryContext ctx = new BinaryContext(BinaryNoopMetadataHandler.instance(), new IgniteConfiguration(), new NullLogger());
    BinaryMarshaller marsh = new BinaryMarshaller();
    marsh.setContext(new MarshallerContextImpl(null, null));
    ctx.configure(marsh, new IgniteConfiguration());
    return new GridBinaryMarshaller(ctx);
}
Also used : MarshallerContextImpl(org.apache.ignite.internal.MarshallerContextImpl) NullLogger(org.apache.ignite.logger.NullLogger) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) BinaryContext(org.apache.ignite.internal.binary.BinaryContext)

Example 34 with BinaryMarshaller

use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.

the class GridMarshallerPerformanceTest method testGridMarshaller.

/**
 * @throws Exception If failed.
 */
public void testGridMarshaller() throws Exception {
    final GridTuple<byte[]> tuple = new GridTuple<>();
    final BinaryMarshaller marsh = createStandaloneBinaryMarshaller();
    IgniteInClosure<TestObject> writer = new CIX1<TestObject>() {

        @Override
        public void applyx(TestObject obj) throws IgniteCheckedException {
            tuple.set(marsh.marshal(obj));
        }
    };
    IgniteOutClosure<TestObject> reader = new COX<TestObject>() {

        @Override
        public TestObject applyx() throws IgniteCheckedException {
            return marsh.unmarshal(tuple.get(), null);
        }
    };
    runTest("GridMarshaller", writer, reader);
}
Also used : CIX1(org.apache.ignite.internal.util.typedef.CIX1) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) GridTuple(org.apache.ignite.internal.util.lang.GridTuple) COX(org.apache.ignite.internal.util.typedef.COX)

Example 35 with BinaryMarshaller

use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.

the class IgniteKernal method fillNodeAttributes.

/**
 * Creates attributes map and fills it in.
 *
 * @param notifyEnabled Update notifier flag.
 * @throws IgniteCheckedException thrown if was unable to set up attribute.
 */
@SuppressWarnings({ "SuspiciousMethodCalls", "unchecked", "TypeMayBeWeakened" })
private void fillNodeAttributes(boolean notifyEnabled) throws IgniteCheckedException {
    ctx.addNodeAttribute(ATTR_DATA_STREAMER_POOL_SIZE, configuration().getDataStreamerThreadPoolSize());
    final String[] incProps = cfg.getIncludeProperties();
    try {
        // Stick all environment settings into node attributes.
        for (Map.Entry<String, String> sysEntry : System.getenv().entrySet()) {
            String name = sysEntry.getKey();
            if (incProps == null || U.containsStringArray(incProps, name, true) || U.isVisorNodeStartProperty(name) || U.isVisorRequiredProperty(name))
                ctx.addNodeAttribute(name, sysEntry.getValue());
        }
        if (log.isDebugEnabled())
            log.debug("Added environment properties to node attributes.");
    } catch (SecurityException e) {
        throw new IgniteCheckedException("Failed to add environment properties to node attributes due to " + "security violation: " + e.getMessage());
    }
    try {
        // identical names from environment properties.
        for (Map.Entry<Object, Object> e : snapshot().entrySet()) {
            String key = (String) e.getKey();
            if (incProps == null || U.containsStringArray(incProps, key, true) || U.isVisorRequiredProperty(key)) {
                Object val = ctx.nodeAttribute(key);
                if (val != null && !val.equals(e.getValue()))
                    U.warn(log, "System property will override environment variable with the same name: " + key);
                ctx.addNodeAttribute(key, e.getValue());
            }
        }
        ctx.addNodeAttribute(IgniteNodeAttributes.ATTR_UPDATE_NOTIFIER_ENABLED, notifyEnabled);
        if (log.isDebugEnabled())
            log.debug("Added system properties to node attributes.");
    } catch (SecurityException e) {
        throw new IgniteCheckedException("Failed to add system properties to node attributes due to security " + "violation: " + e.getMessage());
    }
    // Add local network IPs and MACs.
    // Exclude loopbacks.
    String ips = F.concat(U.allLocalIps(), ", ");
    // Only enabled network interfaces.
    String macs = F.concat(U.allLocalMACs(), ", ");
    // Ack network context.
    if (log.isInfoEnabled()) {
        log.info("Non-loopback local IPs: " + (F.isEmpty(ips) ? "N/A" : ips));
        log.info("Enabled local MACs: " + (F.isEmpty(macs) ? "N/A" : macs));
    }
    // Warn about loopback.
    if (ips.isEmpty() && macs.isEmpty())
        U.warn(log, "Ignite is starting on loopback address... Only nodes on the same physical " + "computer can participate in topology.", "Ignite is starting on loopback address...");
    // Stick in network context into attributes.
    add(ATTR_IPS, (ips.isEmpty() ? "" : ips));
    add(ATTR_MACS, (macs.isEmpty() ? "" : macs));
    // Stick in some system level attributes
    add(ATTR_JIT_NAME, U.getCompilerMx() == null ? "" : U.getCompilerMx().getName());
    add(ATTR_BUILD_VER, VER_STR);
    add(ATTR_BUILD_DATE, BUILD_TSTAMP_STR);
    add(ATTR_MARSHALLER, cfg.getMarshaller().getClass().getName());
    add(ATTR_MARSHALLER_USE_DFLT_SUID, getBoolean(IGNITE_OPTIMIZED_MARSHALLER_USE_DEFAULT_SUID, OptimizedMarshaller.USE_DFLT_SUID));
    add(ATTR_LATE_AFFINITY_ASSIGNMENT, cfg.isLateAffinityAssignment());
    if (cfg.getMarshaller() instanceof BinaryMarshaller) {
        add(ATTR_MARSHALLER_COMPACT_FOOTER, cfg.getBinaryConfiguration() == null ? BinaryConfiguration.DFLT_COMPACT_FOOTER : cfg.getBinaryConfiguration().isCompactFooter());
        add(ATTR_MARSHALLER_USE_BINARY_STRING_SER_VER_2, getBoolean(IGNITE_BINARY_MARSHALLER_USE_STRING_SERIALIZATION_VER_2, BinaryUtils.USE_STR_SERIALIZATION_VER_2));
    }
    add(ATTR_USER_NAME, System.getProperty("user.name"));
    add(ATTR_IGNITE_INSTANCE_NAME, igniteInstanceName);
    add(ATTR_PEER_CLASSLOADING, cfg.isPeerClassLoadingEnabled());
    add(ATTR_DEPLOYMENT_MODE, cfg.getDeploymentMode());
    add(ATTR_LANG_RUNTIME, getLanguage());
    add(ATTR_JVM_PID, U.jvmPid());
    add(ATTR_CLIENT_MODE, cfg.isClientMode());
    add(ATTR_CONSISTENCY_CHECK_SKIPPED, getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK));
    if (cfg.getConsistentId() != null)
        add(ATTR_NODE_CONSISTENT_ID, cfg.getConsistentId());
    // Build a string from JVM arguments, because parameters with spaces are split.
    SB jvmArgs = new SB(512);
    for (String arg : U.jvmArgs()) {
        if (arg.startsWith("-"))
            jvmArgs.a("@@@");
        else
            jvmArgs.a(' ');
        jvmArgs.a(arg);
    }
    // Add it to attributes.
    add(ATTR_JVM_ARGS, jvmArgs.toString());
    // Check daemon system property and override configuration if it's set.
    if (isDaemon())
        add(ATTR_DAEMON, "true");
    // node attribute won't be set.
    if (isJmxRemoteEnabled()) {
        String portStr = System.getProperty("com.sun.management.jmxremote.port");
        if (portStr != null)
            try {
                add(ATTR_JMX_PORT, Integer.parseInt(portStr));
            } catch (NumberFormatException ignore) {
            // No-op.
            }
    }
    // Whether restart is enabled and stick the attribute.
    add(ATTR_RESTART_ENABLED, Boolean.toString(isRestartEnabled()));
    // Save port range, port numbers will be stored by rest processor at runtime.
    if (cfg.getConnectorConfiguration() != null)
        add(ATTR_REST_PORT_RANGE, cfg.getConnectorConfiguration().getPortRange());
    // Save data storage configuration.
    addDataStorageConfigurationAttributes();
    // Save transactions configuration.
    add(ATTR_TX_CONFIG, cfg.getTransactionConfiguration());
    // Stick in SPI versions and classes attributes.
    addSpiAttributes(cfg.getCollisionSpi());
    addSpiAttributes(cfg.getDiscoverySpi());
    addSpiAttributes(cfg.getFailoverSpi());
    addSpiAttributes(cfg.getCommunicationSpi());
    addSpiAttributes(cfg.getEventStorageSpi());
    addSpiAttributes(cfg.getCheckpointSpi());
    addSpiAttributes(cfg.getLoadBalancingSpi());
    addSpiAttributes(cfg.getDeploymentSpi());
    // Set user attributes for this node.
    if (cfg.getUserAttributes() != null) {
        for (Map.Entry<String, ?> e : cfg.getUserAttributes().entrySet()) {
            if (ctx.hasNodeAttribute(e.getKey()))
                U.warn(log, "User or internal attribute has the same name as environment or system " + "property and will take precedence: " + e.getKey());
            ctx.addNodeAttribute(e.getKey(), e.getValue());
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) Map(java.util.Map) HashMap(java.util.HashMap) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Aggregations

BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)93 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)61 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)34 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)22 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)14 Ignite (org.apache.ignite.Ignite)9 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)9 GridBinaryMarshaller (org.apache.ignite.internal.binary.GridBinaryMarshaller)9 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)8 ArrayList (java.util.ArrayList)7 BinaryObject (org.apache.ignite.binary.BinaryObject)7 Marshaller (org.apache.ignite.marshaller.Marshaller)7 IgniteException (org.apache.ignite.IgniteException)6 NullLogger (org.apache.ignite.logger.NullLogger)6 TcpDiscoveryVmIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder)6 HashMap (java.util.HashMap)5 CacheKeyConfiguration (org.apache.ignite.cache.CacheKeyConfiguration)5 MarshallerContextTestImpl (org.apache.ignite.marshaller.MarshallerContextTestImpl)5 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)4 JdkMarshaller (org.apache.ignite.marshaller.jdk.JdkMarshaller)4