Example #1
0
  @Override
  public synchronized void join(
      String theClientName, ObjectReceiver theClient, String theApplicationName) {
    try {
      Tracer.info(this, "Entering Session Join");
      SessionJoinInformationUpdated.newCase(
          CommunicatorSelector.getProcessName(), theClientName, theApplicationName, myName, this);
      JoinInfo retVal = new JoinInfo();
      retVal.newSession = clients.size() == 0;
      ProcessGroup processGroupRemote = multicastGroups.get(theApplicationName);
      ProcessGroupLocal procesGroupLocal = localProcessGroups.get(theApplicationName);
      retVal.newApplication = processGroupRemote == null;

      if (processGroupRemote == null) {
        MulticastGroupCreated.newCase(CommunicatorSelector.getProcessName(), myName, this);
        AProcessGroup processGroup = new AProcessGroup(myName, theApplicationName, null);
        procesGroupLocal = processGroup;
        addSessionListenerLocal(procesGroupLocal);
        processGroupRemote = (ProcessGroup) UnicastRemoteObject.exportObject(processGroup, 0);
        multicastGroups.put(theApplicationName, processGroupRemote);
        localProcessGroups.put(theApplicationName, procesGroupLocal);
      }
      clients.put(theClient, theClientName);
      addSessionListener(theClient);
      notifyClientJoinedRemote(
          processGroupRemote,
          toSerializedProcesstGroups(),
          clients,
          myName,
          theClientName,
          theClient,
          theApplicationName,
          retVal.newSession,
          retVal.newApplication);
      notifyClientJoinedLocal(
          procesGroupLocal,
          toSerializedProcesstGroups(),
          clients,
          myName,
          theClientName,
          theClient,
          theApplicationName,
          retVal.newSession,
          retVal.newApplication);
      Tracer.info(this, "Leaving Session Join");
      // why was this commented out?
      ServerClientJoined.newCase(
          CommunicatorSelector.getProcessName(), theClientName, theApplicationName, myName, this);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return;
  }
Example #2
0
 @Override
 public SemiJoin copy(
     RelTraitSet traitSet,
     RexNode condition,
     RelNode left,
     RelNode right,
     JoinRelType joinType,
     boolean semiJoinDone) {
   assert joinType == JoinRelType.INNER;
   final JoinInfo joinInfo = JoinInfo.of(left, right, condition);
   assert joinInfo.isEqui();
   return new SemiJoin(
       getCluster(), traitSet, left, right, condition, joinInfo.leftKeys, joinInfo.rightKeys);
 }
  public Boolean areColumnsUnique(JoinRelBase rel, BitSet columns, boolean ignoreNulls) {
    if (columns.cardinality() == 0) {
      return false;
    }

    final RelNode left = rel.getLeft();
    final RelNode right = rel.getRight();

    // Divide up the input column mask into column masks for the left and
    // right sides of the join
    BitSet leftColumns = new BitSet();
    BitSet rightColumns = new BitSet();
    int nLeftColumns = left.getRowType().getFieldCount();
    for (int bit : BitSets.toIter(columns)) {
      if (bit < nLeftColumns) {
        leftColumns.set(bit);
      } else {
        rightColumns.set(bit - nLeftColumns);
      }
    }

    // If the original column mask contains columns from both the left and
    // right hand side, then the columns are unique if and only if they're
    // unique for their respective join inputs
    Boolean leftUnique = RelMetadataQuery.areColumnsUnique(left, leftColumns, ignoreNulls);
    Boolean rightUnique = RelMetadataQuery.areColumnsUnique(right, rightColumns, ignoreNulls);
    if ((leftColumns.cardinality() > 0) && (rightColumns.cardinality() > 0)) {
      if ((leftUnique == null) || (rightUnique == null)) {
        return null;
      } else {
        return leftUnique && rightUnique;
      }
    }

    // If we're only trying to determine uniqueness for columns that
    // originate from one join input, then determine if the equijoin
    // columns from the other join input are unique.  If they are, then
    // the columns are unique for the entire join if they're unique for
    // the corresponding join input, provided that input is not null
    // generating.
    final JoinInfo joinInfo = rel.analyzeCondition();
    if (leftColumns.cardinality() > 0) {
      if (rel.getJoinType().generatesNullsOnLeft()) {
        return false;
      }
      Boolean rightJoinColsUnique =
          RelMetadataQuery.areColumnsUnique(right, joinInfo.rightSet(), ignoreNulls);
      if ((rightJoinColsUnique == null) || (leftUnique == null)) {
        return null;
      }
      return rightJoinColsUnique && leftUnique;
    } else if (rightColumns.cardinality() > 0) {
      if (rel.getJoinType().generatesNullsOnRight()) {
        return false;
      }
      Boolean leftJoinColsUnique =
          RelMetadataQuery.areColumnsUnique(left, joinInfo.leftSet(), ignoreNulls);
      if ((leftJoinColsUnique == null) || (rightUnique == null)) {
        return null;
      }
      return leftJoinColsUnique && rightUnique;
    }

    throw new AssertionError();
  }