コード例 #1
0
  /** {@inheritDoc} */
  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    depEnabled = in.readBoolean();

    if (depEnabled) {
      topicBytes = U.readByteArray(in);
      predBytes = U.readByteArray(in);
      clsName = U.readString(in);
      depInfo = (GridDeploymentInfoBean) in.readObject();
    } else {
      topic = in.readObject();
      pred = (GridBiPredicate<UUID, Object>) in.readObject();
    }
  }
コード例 #2
0
  /** {@inheritDoc} */
  @Override
  public void writeExternal(ObjectOutput out) throws IOException {
    out.writeBoolean(depEnabled);

    if (depEnabled) {
      U.writeByteArray(out, topicBytes);
      U.writeByteArray(out, predBytes);
      U.writeString(out, clsName);
      out.writeObject(depInfo);
    } else {
      out.writeObject(topic);
      out.writeObject(pred);
    }
  }
コード例 #3
0
  /** {@inheritDoc} */
  @Override
  public void p2pMarshal(GridKernalContext ctx) throws GridException {
    assert ctx != null;
    assert ctx.config().isPeerClassLoadingEnabled();

    if (topic != null) topicBytes = ctx.config().getMarshaller().marshal(topic);

    predBytes = ctx.config().getMarshaller().marshal(pred);

    GridPeerDeployAware pda = U.peerDeployAware0(topic, pred);

    clsName = pda.deployClass().getName();

    GridDeployment dep = ctx.deploy().deploy(pda.deployClass(), pda.classLoader());

    if (dep == null) throw new GridDeploymentException("Failed to deploy message listener.");

    depInfo = new GridDeploymentInfoBean(dep);

    depEnabled = true;
  }
コード例 #4
0
  /** {@inheritDoc} */
  @Override
  public void execute(@Nullable GridProjection prj) throws GridException {
    if (cb == null)
      throw new IllegalStateException("Mandatory local callback is not set for the query: " + this);

    if (prj == null) prj = ctx.grid();

    prj = prj.forCache(ctx.name());

    if (prj.nodes().isEmpty())
      throw new GridTopologyException("Failed to execute query (projection is empty): " + this);

    GridCacheMode mode = ctx.config().getCacheMode();

    if (mode == LOCAL || mode == REPLICATED) {
      Collection<GridNode> nodes = prj.nodes();

      GridNode node = nodes.contains(ctx.localNode()) ? ctx.localNode() : F.rand(nodes);

      assert node != null;

      if (nodes.size() > 1 && !ctx.cache().isDrSystemCache()) {
        if (node.id().equals(ctx.localNodeId()))
          U.warn(
              log,
              "Continuous query for "
                  + mode
                  + " cache can be run only on local node. "
                  + "Will execute query locally: "
                  + this);
        else
          U.warn(
              log,
              "Continuous query for "
                  + mode
                  + " cache can be run only on single node. "
                  + "Will execute query on remote node [qry="
                  + this
                  + ", node="
                  + node
                  + ']');
      }

      prj = prj.forNode(node);
    }

    closeLock.lock();

    try {
      if (routineId != null)
        throw new IllegalStateException("Continuous query can't be executed twice.");

      guard.block();

      GridContinuousHandler hnd =
          new GridCacheContinuousQueryHandler<>(ctx.name(), topic, cb, filter, prjPred);

      routineId =
          ctx.kernalContext()
              .continuous()
              .startRoutine(hnd, bufSize, timeInterval, autoUnsubscribe, prj.predicate())
              .get();
    } finally {
      closeLock.unlock();
    }
  }