Skip to content

Commit

Permalink
Implementing syncTriggers and everything related.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmichalek committed Oct 9, 2015
1 parent 337d819 commit e661cd5
Show file tree
Hide file tree
Showing 16 changed files with 413 additions and 19 deletions.
2 changes: 2 additions & 0 deletions symmetric-client-clib/inc/core/SymEngine.h
Expand Up @@ -37,6 +37,7 @@
#include "service/RegistrationService.h"
#include "service/DataLoaderService.h"
#include "service/IncomingBatchService.h"
#include "service/ConfigurationService.h"
#include "transport/TransportManagerFactory.h"
#include "transport/TransportManager.h"
#include "common/Constants.h"
Expand All @@ -54,6 +55,7 @@ typedef struct SymEngine {
SymPullService *pullService;
SymNodeService *nodeService;
SymIncomingBatchService *incomingBatchService;
SymConfigurationService *configurationService;

unsigned short (*start)(struct SymEngine *this);
unsigned short (*stop)(struct SymEngine *this);
Expand Down
1 change: 1 addition & 0 deletions symmetric-client-clib/inc/db/platform/DatabasePlatform.h
Expand Up @@ -48,6 +48,7 @@ typedef struct SymDatabasePlatform {
SymSqlTemplate * (*getSqlTemplate)(struct SymDatabasePlatform *this);
SymTable * (*getTableFromCache)(struct SymDatabasePlatform *this, char *catalog, char *schema, char *tableName, unsigned int forceReread);
SymTable * (*readTableFromDatabase)(struct SymDatabasePlatform *this, char *catalog, char *schema, char *tableName);
void (*resetCachedTableModel)(struct SymDatabasePlatform *this);
void (*destroy)(void *this);
} SymDatabasePlatform;

Expand Down
2 changes: 1 addition & 1 deletion symmetric-client-clib/inc/model/NodeGroupLink.h
Expand Up @@ -19,7 +19,7 @@
* under the License.
*/
#ifndef SYM_NODE_GROUP_LINK_H
#define SYM_NODE_GROU_LINK_H
#define SYM_NODE_GROUP_LINK_H

#include <stdlib.h>
#include "util/Date.h"
Expand Down
34 changes: 34 additions & 0 deletions symmetric-client-clib/inc/model/Router.h
@@ -0,0 +1,34 @@
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#ifndef INC_MODEL_ROUTER_H_
#define INC_MODEL_ROUTER_H_

#include <stdlib.h>


typedef struct SymRouter {
char *routerId;
void (*destroy)(struct SymRouter *this);
} SymRouter;

SymRouter * SymRouter_new(SymRouter *this);

#endif /* INC_MODEL_ROUTER_H_ */
34 changes: 34 additions & 0 deletions symmetric-client-clib/inc/model/Trigger.h
@@ -0,0 +1,34 @@
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#ifndef INC_MODEL_TRIGGER_H_
#define INC_MODEL_TRIGGER_H_

#include <stdlib.h>


typedef struct SymTrigger {

void (*destroy)(struct SymTrigger *this);
} SymTrigger;

SymTrigger * SymTrigger_new(SymTrigger *this);

#endif /* INC_MODEL_TRIGGER_H_ */
34 changes: 34 additions & 0 deletions symmetric-client-clib/inc/model/TriggerRouter.h
@@ -0,0 +1,34 @@
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#ifndef INC_MODEL_TRIGGERROUTER_H_
#define INC_MODEL_TRIGGERROUTER_H_

#include <stdlib.h>
#include "model/Trigger.h"

typedef struct SymTriggerRouter {
SymTrigger *trigger;
void (*destroy)(struct SymTriggerRouter *this);
} SymTriggerRouter;

SymTriggerRouter * SymTriggerRouter_new(SymTriggerRouter *this);

#endif /* INC_MODEL_TRIGGERROUTER_H_ */
4 changes: 4 additions & 0 deletions symmetric-client-clib/inc/service/ConfigurationService.h
Expand Up @@ -27,6 +27,10 @@

typedef struct SymConfigurationService {
SymList * (*getNodeChannels)(struct SymConfigurationService *this);
SymList * (*clearCache)(struct SymConfigurationService *this);
SymList * (*destroy)(struct SymConfigurationService *this);
} SymConfigurationService;

SymConfigurationService * SymConfigurationService_new(SymConfigurationService *this);

#endif
46 changes: 44 additions & 2 deletions symmetric-client-clib/inc/service/TriggerRouterService.h
Expand Up @@ -25,15 +25,57 @@
#include <stdlib.h>
#include "db/model/Table.h"
#include "service/ParameterService.h"
#include "service/ConfigurationService.h"
#include "db/platform/DatabasePlatform.h"
#include "util/Map.h"
#include "util/List.h"

typedef struct SymTriggerSelector {
SymList* triggers;
struct SymList * (*select)(struct SymTriggerSelector *this);
void (*destroy)(struct SymTriggerSelector * this);
} SymTriggerSelector;

SymTriggerSelector * SymTriggerSelector_new(SymTriggerSelector *this, SymList *triggers);


typedef struct SymTriggerRoutersCache {
SymMap* triggerRoutersByTriggerId;
SymMap* routersByRouterId;
void (*destroy)(struct SymTriggerSelector * this);
} SymTriggerRoutersCache;

SymTriggerRoutersCache * SymTriggerRoutersCache_new(SymTriggerRoutersCache *this);


typedef struct SymTriggerRouterService {
long routersCacheTime;
SymMap* routersCache;

SymList* triggerRoutersCache;
long triggerRouterPerNodeCacheTime;

SymMap* triggersCache;
long triggersCacheTime;
long triggerRoutersCacheTime;

SymMap* triggerRouterCacheByNodeGroupId;

long triggerRouterPerChannelCacheTime;

SymParameterService *parameterService;
SymConfigurationService *configurationService;
SymDatabasePlatform *platform;

int (*syncTriggers)(struct SymTriggerRouterService *this, SymStringBuilder *sqlBuffer, unsigned short force);
int (*syncTriggers_withTable)(struct SymTriggerRouterService *this, SymTable *table, unsigned short force);
int (*syncTriggersWithTable)(struct SymTriggerRouterService *this, SymTable *table, unsigned short force);
void (*clearCache)(struct SymTriggerRouterService *this);
SymMap* (*getTriggerRoutersForCurrentNode)(struct SymTriggerRouterService *this, unsigned short refreshCache);
SymList* (*getTriggersForCurrentNode)(struct SymTriggerRouterService *this, unsigned short refreshCache);
SymTriggerRoutersCache* (*getTriggerRoutersCacheForCurrentNode)(struct SymTriggerRouterService *this, unsigned short refreshCache);
void (*destroy)(struct SymTriggerRouterService *this);
} SymTriggerRouterService;

SymTriggerRouterService * SymTriggerRouterService_new(SymTriggerRouterService * this);
SymTriggerRouterService * SymTriggerRouterService_new(SymTriggerRouterService * this, SymParameterService *parameterService, SymDatabasePlatform *platform, SymConfigurationService *configurationService);

#endif
19 changes: 10 additions & 9 deletions symmetric-client-clib/src/core/SymEngine.c
Expand Up @@ -52,6 +52,7 @@ unsigned short SymEngine_start(SymEngine *this) {
SymNode *node = this->nodeService->findIdentity(this->nodeService);

if (node != NULL) {

if (strcmp(node->externalId, this->parameterService->getExternalId(this->parameterService)) != 0 ||
strcmp(node->nodeGroupId, this->parameterService->getNodeGroupId(this->parameterService)) != 0) {
SymLog_error("The configured state does not match recorded database state. The recorded external id is %s while the configured external id is %s. The recorded node group id is %s while the configured node group id is %s",
Expand All @@ -60,13 +61,12 @@ unsigned short SymEngine_start(SymEngine *this) {
} else {
SymLog_info("Starting registered node [group=%s, id=%s, externalId=%s]", node->nodeGroupId, node->nodeId, node->externalId);

// TODO
// if (this->parameterService->is(this->parameterService, AUTO_SYNC_TRIGGERS_AT_STARTUP, 0)) {
// this->triggerRouterService->syncTriggers(this->triggerRouterService, NULL, 0);
// }
// else {
// SymLog_info("%s is turned off.", AUTO_SYNC_TRIGGERS_AT_STARTUP);
// }
if (this->parameterService->is(this->parameterService, AUTO_SYNC_TRIGGERS_AT_STARTUP, 1)) {
this->triggerRouterService->syncTriggers(this->triggerRouterService, NULL, 0);
}
else {
SymLog_info("%s is turned off.", AUTO_SYNC_TRIGGERS_AT_STARTUP);
}

// TODO: if HEARTBEAT_SYNC_ON_STARTUP
}
Expand All @@ -90,7 +90,6 @@ unsigned short SymEngine_start(SymEngine *this) {
}

unsigned short SymEngine_stop(SymEngine *this) {
SymLog_info("Stopping\n");
SymLog_info("Stopping SymmetricDS externalId=%s version=%s database=%s",
this->parameterService->getExternalId(this->parameterService), SYM_VERSION, this->platform->name);

Expand Down Expand Up @@ -130,8 +129,10 @@ SymEngine * SymEngine_new(SymEngine *this, SymProperties *properties) {
this->platform = SymDatabasePlatformFactory_create(properties);
this->dialect = SymDialectFactory_create(this->platform);

this->configurationService = SymConfigurationService_new(NULL);

this->parameterService = SymParameterService_new(NULL, properties);
this->triggerRouterService = SymTriggerRouterService_new(NULL);
this->triggerRouterService = SymTriggerRouterService_new(NULL, this->parameterService, this->platform, this->configurationService);
this->transportManager = SymTransportManagerFactory_create(SYM_PROTOCOL_HTTP, this->parameterService);
this->nodeService = SymNodeService_new(NULL, this->platform);
this->incomingBatchService = SymIncomingBatchService_new(NULL, this->platform, this->parameterService);
Expand Down
5 changes: 5 additions & 0 deletions symmetric-client-clib/src/db/platform/DatabasePlatform.c
Expand Up @@ -36,13 +36,18 @@ SymTable * SymDatabasePlatform_readTableFromDatabase(SymDatabasePlatform *this,
return table;
}

void SymDatabasePlatform_resetCachedTableModel(SymDatabasePlatform *this) {
// TODO: implement along with caching.
}

void SymDatabasePlatform_destroy(SymDatabasePlatform *this) {
}

SymDatabasePlatform * SymDatabasePlatform_new(SymDatabasePlatform *this) {
if (this != NULL) {
this->getTableFromCache = (void *) &SymDatabasePlatform_getTableFromCache;
this->readTableFromDatabase = (void *) &SymDatabasePlatform_readTableFromDatabase;
this->resetCachedTableModel = (void *)&SymDatabasePlatform_resetCachedTableModel;
this->destroy = (void *) &SymDatabasePlatform_destroy;
}
return this;
Expand Down
Expand Up @@ -81,7 +81,7 @@ SymSqlitePlatform * SymSqlitePlatform_new(SymSqlitePlatform *this, SymProperties

if (sqlite3_open_v2(filename, &this->db,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_URI, NULL)) {
SymLog_info("Can't open database: %s", sqlite3_errmsg(this->db));
SymLog_error("Can't open database: %s", sqlite3_errmsg(this->db));
sqlite3_close(this->db);
return NULL;
}
Expand Down
34 changes: 34 additions & 0 deletions symmetric-client-clib/src/model/Router.c
@@ -0,0 +1,34 @@
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "model/Router.h"


void SymRouter_destroy(SymRouter *this) {
free(this);
}

SymRouter * SymRouter_new(SymRouter *this) {
if (this == NULL) {
this = (SymRouter *) calloc(1, sizeof(SymRouter));
}
this->destroy = (void *) &SymRouter_destroy;
return this;
}
34 changes: 34 additions & 0 deletions symmetric-client-clib/src/model/Trigger.c
@@ -0,0 +1,34 @@
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "model/Trigger.h"


void SymTrigger_destroy(SymTrigger *this) {
free(this);
}

SymTrigger * SymTrigger_new(SymTrigger *this) {
if (this == NULL) {
this = (SymTrigger *) calloc(1, sizeof(SymTrigger));
}
this->destroy = (void *) &SymTrigger_destroy;
return this;
}
33 changes: 33 additions & 0 deletions symmetric-client-clib/src/model/TriggerRouter.c
@@ -0,0 +1,33 @@
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "model/TriggerRouter.h"

void SymTriggerRouter_destroy(SymTriggerRouter *this) {
free(this);
}

SymTriggerRouter * SymTriggerRouter_new(SymTriggerRouter *this) {
if (this == NULL) {
this = (SymTriggerRouter *) calloc(1, sizeof(SymTriggerRouter));
}
this->destroy = (void *) &SymTriggerRouter_destroy;
return this;
}

0 comments on commit e661cd5

Please sign in to comment.