Пример #1
0
 /**
  * produce
  * Transfer the user command to the core which will eventually send the command to the server
  * handle the command status received by the server
  * @param command
  * @param <T>
  * @throws PlanckDBException
  * @throws EntityLockException
  */
 public void produce(Command command)
 {
     if(command.isModeCommand()){
     //noinspection SynchronizationOnLocalVariableOrMethodParameter
     lock(command){
         getCore().consume(command);
         CommandStatus status = command.getStatus();
         if( ! CommandStatus.success.Equals(status)){
             if(CommandStatus.notNodeOwner.Equals(status)){
                 throw new EntityLockException(status,status.getMessage());
             }else{
                 throw new PlanckDBException(status,status.getMessage());
             }
         }
         try {
             Monitor.Wait(command,120000000);
         } catch (Exception e) {
             throw new PlanckDBException(status,"Fatal exception in command synchronization process ( while waiting for awake notification, an  InterruptedException occurred. ");
         }
     }
     }else{
     getCore().consume(command);
     }
     CommandStatus commandStatus =command.getStatus();
     if (!CommandStatus.success.Equals(commandStatus))
     {
     throw new PlanckDBException(commandStatus, commandStatus.getMessage() + " schema : " + sessionMetaData.getSchemaName() + " user " + sessionMetaData.getUserName());
     }
 }
Пример #2
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);
                    }
                }
            }
        }