Search in sources :

Example 16 with Marshaller

use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.

the class GridServiceProcessor method prepareServiceConfigurations.

/**
 * @param cfgs Service configurations.
 * @param dfltNodeFilter Default NodeFilter.
 * @return Configurations to deploy.
 */
private PreparedConfigurations prepareServiceConfigurations(Collection<ServiceConfiguration> cfgs, IgnitePredicate<ClusterNode> dfltNodeFilter) {
    List<ServiceConfiguration> cfgsCp = new ArrayList<>(cfgs.size());
    Marshaller marsh = ctx.config().getMarshaller();
    List<GridServiceDeploymentFuture> failedFuts = null;
    for (ServiceConfiguration cfg : cfgs) {
        Exception err = null;
        // or only on server nodes if no projection .
        if (cfg.getNodeFilter() == null && dfltNodeFilter != null)
            cfg.setNodeFilter(dfltNodeFilter);
        try {
            validate(cfg);
        } catch (Exception e) {
            U.error(log, "Failed to validate service configuration [name=" + cfg.getName() + ", srvc=" + cfg.getService() + ']', e);
            err = e;
        }
        if (err == null) {
            try {
                ctx.security().authorize(cfg.getName(), SecurityPermission.SERVICE_DEPLOY, null);
            } catch (Exception e) {
                U.error(log, "Failed to authorize service creation [name=" + cfg.getName() + ", srvc=" + cfg.getService() + ']', e);
                err = e;
            }
        }
        if (err == null) {
            try {
                byte[] srvcBytes = U.marshal(marsh, cfg.getService());
                cfgsCp.add(new LazyServiceConfiguration(cfg, srvcBytes));
            } catch (Exception e) {
                U.error(log, "Failed to marshal service with configured marshaller [name=" + cfg.getName() + ", srvc=" + cfg.getService() + ", marsh=" + marsh + "]", e);
                err = e;
            }
        }
        if (err != null) {
            if (failedFuts == null)
                failedFuts = new ArrayList<>();
            GridServiceDeploymentFuture fut = new GridServiceDeploymentFuture(cfg);
            fut.onDone(err);
            failedFuts.add(fut);
        }
    }
    return new PreparedConfigurations(cfgsCp, failedFuts);
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) ArrayList(java.util.ArrayList) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) SecurityException(org.apache.ignite.plugin.security.SecurityException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 17 with Marshaller

use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.

the class GridServiceProcessor method copyAndInject.

/**
 * @param cfg Service configuration.
 * @return Copy of service.
 * @throws IgniteCheckedException If failed.
 */
private Service copyAndInject(ServiceConfiguration cfg) throws IgniteCheckedException {
    Marshaller m = ctx.config().getMarshaller();
    if (cfg instanceof LazyServiceConfiguration) {
        byte[] bytes = ((LazyServiceConfiguration) cfg).serviceBytes();
        Service srvc = U.unmarshal(m, bytes, U.resolveClassLoader(null, ctx.config()));
        ctx.resource().inject(srvc);
        return srvc;
    } else {
        Service svc = cfg.getService();
        try {
            byte[] bytes = U.marshal(m, svc);
            Service cp = U.unmarshal(m, bytes, U.resolveClassLoader(svc.getClass().getClassLoader(), ctx.config()));
            ctx.resource().inject(cp);
            return cp;
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to copy service (will reuse same instance): " + svc.getClass(), e);
            return svc;
        }
    }
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ExecutorService(java.util.concurrent.ExecutorService) Service(org.apache.ignite.services.Service)

Example 18 with Marshaller

use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.

the class GridSessionCheckpointAbstractSelfTest method checkFinishedState.

/**
 * @param sesKey Session key.
 * @param globalKey Global key.
 * @param globalState Global state.
 * @throws Exception If check failed.
 */
private void checkFinishedState(String sesKey, String globalKey, String globalState) throws Exception {
    byte[] serState = spi.loadCheckpoint(sesKey);
    assert serState == null : "Session scope variable is not null: " + Arrays.toString(serState);
    serState = spi.loadCheckpoint(globalKey);
    Marshaller marshaller = IgniteTestResources.getMarshaller();
    assert marshaller != null;
    String state = marshaller.unmarshal(serState, getClass().getClassLoader());
    assert state != null : "Global state is missing: " + globalKey;
    assert state.equals(globalState) : "Invalid state value: " + state;
    spi.removeCheckpoint(globalKey);
    Object cp = spi.loadCheckpoint(globalKey);
    assert cp == null;
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller)

Example 19 with Marshaller

use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.

the class GridCacheQueryResponse method unmarshalCollection0.

/**
 * @param byteCol Collection to unmarshal.
 * @param ctx Context.
 * @param ldr Loader.
 * @return Unmarshalled collection.
 * @throws IgniteCheckedException If failed.
 */
@Nullable
protected <T> List<T> unmarshalCollection0(@Nullable Collection<byte[]> byteCol, GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException {
    assert ldr != null;
    assert ctx != null;
    if (byteCol == null)
        return null;
    List<T> col = new ArrayList<>(byteCol.size());
    Marshaller marsh = ctx.marshaller();
    ClassLoader ldr0 = U.resolveClassLoader(ldr, ctx.gridConfig());
    CacheObjectContext cacheObjCtx = null;
    for (byte[] bytes : byteCol) {
        Object obj = bytes == null ? null : marsh.<T>unmarshal(bytes, ldr0);
        if (obj instanceof Map.Entry) {
            Object key = ((Map.Entry) obj).getKey();
            if (key instanceof KeyCacheObject) {
                if (cacheObjCtx == null)
                    cacheObjCtx = ctx.cacheContext(cacheId).cacheObjectContext();
                ((KeyCacheObject) key).finishUnmarshal(cacheObjCtx, ldr0);
            }
        }
        col.add((T) obj);
    }
    return col;
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) ArrayList(java.util.ArrayList) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with Marshaller

use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.

the class GridCacheVersionSelfTest method testMarshalling.

/**
 * Test versions marshalling.
 *
 * @throws Exception If failed.
 */
public void testMarshalling() throws Exception {
    GridCacheVersion ver = version(1, 1);
    GridCacheVersionEx verEx = new GridCacheVersionEx(2, 2, 0, ver);
    Marshaller marsh = createStandaloneBinaryMarshaller();
    byte[] verBytes = marsh.marshal(ver);
    byte[] verExBytes = marsh.marshal(verEx);
    GridCacheVersion verNew = marsh.unmarshal(verBytes, Thread.currentThread().getContextClassLoader());
    GridCacheVersionEx verExNew = marsh.unmarshal(verExBytes, Thread.currentThread().getContextClassLoader());
    assert ver.equals(verNew);
    assert verEx.equals(verExNew);
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheVersionEx(org.apache.ignite.internal.processors.cache.version.GridCacheVersionEx) Marshaller(org.apache.ignite.marshaller.Marshaller)

Aggregations

Marshaller (org.apache.ignite.marshaller.Marshaller)46 Externalizable (java.io.Externalizable)8 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 HttpURLConnection (java.net.HttpURLConnection)5 URL (java.net.URL)5 URLConnection (java.net.URLConnection)5 ArrayList (java.util.ArrayList)5 HttpSession (javax.servlet.http.HttpSession)5 IgniteException (org.apache.ignite.IgniteException)5 JdkMarshaller (org.apache.ignite.marshaller.jdk.JdkMarshaller)5 Ignite (org.apache.ignite.Ignite)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 Server (org.eclipse.jetty.server.Server)4 File (java.io.File)2 OutputStream (java.io.OutputStream)2 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)2 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)2 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)2 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)2