ArrayList registryGetAllChildsOfNode(Registry registry,Node nodeObject ,int dept){ ArrayList result=arrayListCreate(); if(dept==0){ return result; } if(nodeObject==NULL){ return result; } NodeInternal* node=(NodeInternal*)nodeObject; if(node!=NULL){ Array array; stringHashmapToArray(node->children,&array); int length=arrayGetLength(array); int i; for(i=0;i<length;i++){ Arc arc=arrayGetObject(array,i); arrayListAddLast(result,arc->child); ArrayList list=registryGetAllChildsOfNode(registry,arc->child,dept-1); arrayListAddAll(result,list); arrayListFree(list); } arrayFree(array); } return result; }
void tcpConnectionWriterRunThread(TcpConnection tcpConnection){ TcpConnectionInternal* internal=(TcpConnectionInternal*)tcpConnection; ArrayList tempList; while(internal->active==TRUE){ environmentThreadLock(internal->thread); tempList=internal->commands; internal->commands=arrayListCreate(); environmentThreadUnlock(internal->thread); int i; int length=arrayListSize(tempList); Command command; for(i=0; i < length;i++){ command=arrayListGetValueAt(tempList,i); int result=tcpConnectionSend(tcpConnection,command); if(result<0){ internal->active=FALSE; distributionManagerHandleTcpConnectionListenerFailure(internal->distributionManager,internal,internal->coreManagerId); //TODO Free the commands return; } commandFree(command); } arrayListFree(tempList); // Lock to synchronize environmentThreadLock(internal->thread); if(arrayListSize(internal->commands)==0){ environmentThreadWait(internal->thread); } environmentThreadUnlock(internal->thread); } internal->readyForCleanup+=WRITER_READY_FOR_CLEANUP; }
ArrayList registrySerializeToCommands(Registry registry){ RegistryInternal* internal=(RegistryInternal*)registry; ArrayList commands=arrayListCreate(); Array nodeArray; hashmapToArray(internal->nodes,&nodeArray); int length=arrayGetLength(nodeArray); int i; int coreManagerId=SERVER_COREMANAGER_ID; int serverSessionId=SERVER_SESSION_ID; for(i=0;i<length;i++){ Node node=arrayGetObject(nodeArray,i); int schemaId=node->schemaId; int locked=node->locked; int version=-1; int commandType=CREATE_NEW_ENTITY; int entityId=node->id; Command command=commandCreate(); commandPush(command,COMMAND_TYPE,INTEGER,&commandType,SIZE_OF_INT); commandPush(command,LOCK,INTEGER,&locked,SIZE_OF_INT); commandPush(command,SCHEMA_ID,INTEGER,&schemaId,SIZE_OF_INT); commandPush(command,ENTITY_ID,INTEGER,&entityId,SIZE_OF_INT); commandPush(command,VERSION,INTEGER,&version,SIZE_OF_INT); commandPush(command,ATTRIBUTES,ATTRIBUTES_MAP,node->attributes,CONTAINER_SIZE); commandPush(command,CORE_MANAGER_ID,INTEGER,&coreManagerId,0); commandPush(command,SESSION_ID,INTEGER,&serverSessionId,0); arrayListAddLast(commands,command); } for(i=0;i<length;i++){ Node node=arrayGetObject(nodeArray,i); NodeInternal* nodeInternal=(NodeInternal*)node; Array children; stringHashmapToArray(nodeInternal->children,&children); int childrenAmount=arrayGetLength(children); int version=-1; int schemaId=node->schemaId; int j; int commandType=ADD_CHILD_ENTITY_TO_PARENT_ENTITY; for(j=0;j<childrenAmount;j++){ Arc childArc=arrayGetObject(children,j); Command command=commandCreate(); commandPush(command,COMMAND_TYPE,INTEGER,&commandType,SIZE_OF_INT); commandPush(command,ENTITY_ID,INTEGER,&node->id,SIZE_OF_INT); commandPush(command,ENTITY_CHILD_ID,INTEGER,&childArc->child->id,SIZE_OF_INT); commandPush(command,SCHEMA_ID,INTEGER,&schemaId,SIZE_OF_INT); commandPush(command,VERSION,INTEGER,&version,SIZE_OF_INT); commandPush(command,CORE_MANAGER_ID,INTEGER,&coreManagerId,SIZE_OF_INT); commandPush(command,SESSION_ID,INTEGER,&serverSessionId,SIZE_OF_INT); commandPush(command,ARC_NAME,BYTE_ARRAY,childArc->arcName,childArc->arcLength); arrayListAddLast(commands,command); } arrayFree(children); } arrayFree(nodeArray); return commands; }
int main(){ struct arrayList* list = arrayListCreate(); arrayListAdd(list, "TOM"); arrayListAdd(list, "JERRY"); arrayListAdd(list, "Song of ice and fire"); arrayListAdd(list, "Game of Throne"); arrayListPrint(list); arrayListDelete(list, 2); arrayListPrint(list); return 0; }
int validationManagerValidateOnCoreExecute(ValidationManager validationManager,Command command,ArrayList commands,int atomic){ int administrator=commandGetInt(command,MARKED_AS_ADMINISTRATOR); if(atomic==TRUE){ return validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,0); }else{ commands =arrayListCreate(); arrayListAddLast(commands,command); int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,0); arrayListFree(commands); return result; } }
/** * AtomicOnlineSchema open;<p> * create new instance of commandsList which will contain all the transactional commands.<p> * create new instance of transactionEntities which will contain a list of the loked entities. */ Transaction transactionCreate(Core core,CommandExecuter commandExecutor,Registry registry,SchemaAdapter schemaAdapter,SessionMetaData sessionMetaData,long lockTimeout){ TransactionInternal*m=(TransactionInternal*)memoryAlloc(sizeof(TransactionInternal)); m->core=core; m->commandExecutor=commandExecutor; m->registry=registry; m->scheamAdapter=schemaAdapter; m->sessionMetaData=sessionMetaData; m->transactionEntities=hashmapCreate(SMALL_CONTAINER_SIZE); m->dirtySet=hashmapCreate(SMALL_CONTAINER_SIZE); m->commandList=arrayListCreate(); m->transaction=NULL; m->lockTimeout=lockTimeout; }
/* * serialize Node; */ int nodeSerialize( Node node,char ** result){ NodeInternal* internal=(NodeInternal*)node; Array attributes; stringHashmapToArray(node->attributes,&attributes); void* attributeBuffer; int attributeLength; int size=SIZE_OF_INT*4; int numberOfAttributes=arrayGetLength(attributes); int i; Attribute attribute; for(i=0;i<numberOfAttributes;i++){ attribute=arrayGetObject(attributes,i); size+=attributeSerializeLocal(attribute,&attributeBuffer); memoryFree(attributeBuffer); } stringHashmapIterate(internal->children,registryUpdateNodeBufferSize,(Object)&size); char * buffer=memoryAlloc(size); *result=buffer; memcpy(buffer+SIZE_OF_INT*0,&(internal->schemaId),SIZE_OF_INT); memcpy(buffer+SIZE_OF_INT*1,&(internal->id),SIZE_OF_INT); memcpy(buffer+SIZE_OF_INT*2,&numberOfAttributes,SIZE_OF_INT); buffer+=SIZE_OF_INT*3; for(i=0;i<numberOfAttributes;i++){ attribute=arrayGetObject(attributes,i); attributeLength=attributeSerializeLocal(attribute,&attributeBuffer); memcpy(buffer,attributeBuffer,attributeLength); buffer+=attributeLength; memoryFree(attributeBuffer); } arrayFree(attributes); ArrayList list=arrayListCreate(); stringHashmapIterate(internal->children,registryCreateChildrenBufferElemrnts,list); int numberOfChildren=arrayListSize(list); memcpy(buffer,&numberOfChildren,SIZE_OF_INT); buffer+=SIZE_OF_INT; int j; for(j=0;j<numberOfChildren;j++){ void* bufferElement=arrayListGetValueAt(list,j); int bufferSize; memcpy(&bufferSize,bufferElement+SIZE_OF_INT,SIZE_OF_INT); memcpy(buffer,bufferElement,SIZE_OF_INT*2+bufferSize); buffer+=SIZE_OF_INT*2+bufferSize; memoryFree(bufferElement); } arrayListFree(list); return size; }
TcpConnection tcpConnectionCreate(DistributionManager distributionManager,int sockfd,int coreManagerId,char* remoteIp,int remotePort){ TcpConnectionInternal* m=(TcpConnectionInternal*)memoryAlloc(sizeof(TcpConnectionInternal)); m->coreManagerId=coreManagerId; m->sockfd=sockfd; m->remoteIp=strdup(remoteIp); m->remoteIpLenght=strlen(remoteIp); m->remotePort=remotePort; m->distributionManager=distributionManager; m->active=TRUE; m->commands=arrayListCreate(); m->readyForCleanup=0; int set = 1; setsockopt(sockfd, SOL_SOCKET, MSG_NOSIGNAL, (void *)&set, sizeof(int)); return m; }
int validationManagerValidateRefferance(ValidationManager validationManager,int entityId){ ValidationManagerStruct* internal=(ValidationManagerStruct*)validationManager; ValidationDataStructure * data; HashMap chidrenMap; hashmapGet(internal->parentChildrenRelationEntities,entityId,&chidrenMap); if(chidrenMap==NULL){ chidrenMap = stringHashmapCreate(SMALL_CONTAINER_SIZE); hashmapPut(internal->parentChildrenRelationEntities,entityId,chidrenMap); } ArrayList parents; hashmapGet(internal->childrenParentRelationEntities,entityId,&parents); if(parents==NULL){ parents = arrayListCreate(); hashmapPut(internal->childrenParentRelationEntities,entityId,parents); } int parentSize=arrayListSize(parents); int childrenSize=stringHashmapLength(chidrenMap); if(parentSize>0||childrenSize>0){ return VALID; }else{ return NO_CHILD_PARENT_RELATION; } }
//Inputs: arrayList //Outputs: nothing //Purpose: create set void listSetCreate(arrayList l) { arrayListCreate(l); return; }