Esempio n. 1
0
 /**
  * consume
  * Discriminate the command handler
  * Called by the core.
  * @param command
  * @throws PlanckDBException
  */
 public void consume(Command command)
 {
     Int32 type=command.getCommandType();
     switch (type){
     case PlanckDBConstants.CREATE_NEW_ENTITY:handleNewItemCommand( command);break;
     case PlanckDBConstants.DELETE_ENTITY:handleRemoveItemCommand(command);break;
     case PlanckDBConstants.ADD_CHILD_ENTITY_TO_PARENT_ENTITY: handleAddChildToParent(command);break;
     case PlanckDBConstants.REMOVE_CHILD_ENTITY_FROM_PARENT_ENTITY:handleRemoveChildFromParent(command);break;
     case PlanckDBConstants.UPDATE_ENTITY: handleUpdateNodeCommand(command);break;
     case PlanckDBConstants.LOCK_ENTITY:handleLockItemCommand(command);break;
     case PlanckDBConstants.ADD_ATTRIBUTE:handleAddAttributeCommand(command);break;
     case PlanckDBConstants.REMOVE_ATTRIBUTE:handleRemoveAttributeCommand(command);break;
     }
     int entityId=command.getEntityId();
     int? commandSchemaId=command.GetSchemaId();
     foreach (Transaction transaction in transactions) {
     if(commandSchemaId!=transaction.schemaId()){
         transaction.getDirtySet().Add(entityId);
     }
     }
 }
Esempio n. 2
0
 public Command revertCommand(Command command)
 {
     int commandType=command.getCommandType();
     Int32 entityId = command.getEntityId();
     Int32 childEntityId = command.getChildEntityId();
     Int32 schemaId=(Int32)command.GetSchemaId();
     Int32 coreManagerId=command.GetCoreManagerKey();
     Int32 sessionId=command.GetSessionId();
     bool lockEntity=command.getLock();
     bool oldLock=command.getOldLock();
     NodeAttribute[] oldAttributes=command.getOldAttributes();
     NodeAttribute[] attributes=command.getAttributes();
     byte[] arcName=command.getArcName();
     long lockTimeout=command.getLockTimeOut();
     switch (commandType){
         case PlanckDBConstants.CREATE_NEW_ENTITY:{
             return buildDeleteNode(entityId,lockEntity,schemaId,coreManagerId,sessionId, lockTimeout, attributes);
         }
         case PlanckDBConstants.DELETE_ENTITY:{
             Command newCommand= buildCreateNode(oldLock,schemaId,coreManagerId,sessionId, lockTimeout, oldAttributes);
             newCommand.Push(PlanckDBConstants.ENTITY_ID, PlanckDBConstants.INTEGER,entityId);
             return newCommand;
         }
         case PlanckDBConstants.ADD_CHILD_ENTITY_TO_PARENT_ENTITY:{
             return buildRemoveChildFromParentNode(entityId,arcName,childEntityId,schemaId,coreManagerId,sessionId, lockTimeout);
         }
         case PlanckDBConstants.REMOVE_CHILD_ENTITY_FROM_PARENT_ENTITY:{
             return buildAddChildToParentNode(entityId,childEntityId,arcName,schemaId,coreManagerId,sessionId, lockTimeout);
         }
         case PlanckDBConstants.UPDATE_ENTITY:{
             Command newCommand = buildUpdateNode(entityId, schemaId, coreManagerId, sessionId, lockTimeout, attributes);
             newCommand.Push(PlanckDBConstants.OLD_ATTRIBUTES, PlanckDBConstants.ATTRIBUTE_MAP,oldAttributes);
             return newCommand;
         }
         case PlanckDBConstants.ADD_ATTRIBUTE:{
             return buildRemoveAttributes(entityId,schemaId,coreManagerId,sessionId,lockTimeout,attributes);
         }
         case PlanckDBConstants.REMOVE_ATTRIBUTE:{
             return buildAddAttributes(entityId,schemaId,coreManagerId,sessionId, lockTimeout, oldAttributes);
         }
     }
     throw  new PlanckDBException("unsupported state the should not reach to this point of the code");
 }
Esempio n. 3
0
        /**
         * this is the heart of the storage,<p>
         * It control all the in coming commands.<p>
         * The method does the following<p>
         * 1. validate the command<p>
         * 2. update the version number and the conflict number (if needed)<p>
         * 3. push the command to the command queue<p>
         */
        public void consume(Command command)
        {
            // update schema and coreManagerKey in command in case that the schema or coreManagerKey fields in the command are null

            if(command.GetSchemaId()<0){
                command.setSchemaId(getSessionMetaData().getSchemaId());
            }
            if(command.GetCoreManagerKey()==null){
                command.setCoreManagerKey(getCoreManager().getKey());
            }

            // you do not have to handle your messages which NetworkProtocolType is multicast
            // because you have already handle them
            NetworkProtocolType type = command.getNetworkProtocolType();
            if(type!=null && isCast(type) && command.GetCoreManagerKey().Equals(getCoreManager().getKey())&&sessionMetaData.GetSessionId()==command.GetSessionId()){
                return;
            }
            //TODO validate message

            if(command.isModeCommand()||command.isAtomicModelCommand()){  // model change commands

                // set version number or distribute
                if(command.getVersion()<0){
                    distributionManager.produceTcp(command);
                    int version =  command.getVersion();
                    // return if command is lock or something was wrong
                    if(version<0|| command.isNotSucceed()){
                        return;
                    }
                }

                if(command.isAtomicModelCommand()){
                    List<Command> commands = command.getCommands();
                    atomicContainer.register(command,commands);
                    foreach (Command newCommand in commands) {
                        commandQueue.pushCommand(newCommand);
                    }
                }else{
                    commandQueue.pushCommand(command);
                }
            }else{
                Int32 commandType = command.getCommandType();
                if(commandType==PlanckDBConstants.READ_LOCK_COMMAND){
                    if( ! command.GetCoreManagerKey().Equals(coreManager.getKey())){
                        List<Command> commands=command.getCommands();
                        bool entityLock=command.isLocked();
                        foreach (Command newCommand in commands) {
                            int entityId=newCommand.getEntityId();
                            int ownerId=newCommand.getOwnerId();
                            if(entityLock){
                                registry.lockEntity(entityId,true,ownerId);
                            }else{
                                registry.lockEntity(entityId,false,PlanckDBConstants.NON_ENTITY_OWNER);
                            }
                        }
                    }else{
                        distributionManager.produceTcp(command);
                    }
                }
            }
        }