Ejemplo n.º 1
0
bool StoreListener::getAttachmentData(const idgs::actor::ActorMessagePtr& msg, idgs::actor::PbMessagePtr& key, idgs::actor::PbMessagePtr& value) {
  protobuf::MessageHelper& helper = idgs::util::singleton<protobuf::MessageHelper>::getInstance();
  const string& keyType = storeConfig->getStoreConfig().key_type();
  key = msg->getAttachement(STORE_ATTACH_KEY);
  if (!key) {
    key = helper.createMessage(keyType);
    if (!key) {
      LOG(ERROR) << "key type " << keyType << " is not registered.";
      return false;
    }

    if (!msg->parseAttachment(STORE_ATTACH_KEY, key.get())) {
      LOG(ERROR) << "invalid key with type " << keyType;
      return false;
    }
  }

  const string& valueType = storeConfig->getStoreConfig().value_type();
  value = msg->getAttachement(STORE_ATTACH_VALUE);
  if (!value) {
    value = helper.createMessage(valueType);
    if (!key) {
      LOG(ERROR) << "value type " << valueType << " is not registered.";
      return false;
    }

    if (!msg->parseAttachment(STORE_ATTACH_VALUE, value.get())) {
      LOG(ERROR) << "invalid value with type " << valueType;
      return false;
    }
  }

  return true;
}
Ejemplo n.º 2
0
void ListenerManager::handleListenerInsert(const idgs::actor::ActorMessagePtr& msg) {
  pb::InsertRequest* request = dynamic_cast<pb::InsertRequest*>(msg->getPayload().get());
  const std::string& storeName = request->store_name();
  std::shared_ptr<StoreConfigWrapper> config;
  auto code = idgs::util::singleton<DataStore>::getInstance().getStoreConfigWrappers().getStoreConfig(storeName, config);
  if (code != RC_SUCCESS) {
    LOG(ERROR) << "store " << storeName << " is not found.";
    return;
  }

  pb::StoreListenerInfo* listenerInfo = new pb::StoreListenerInfo;
  if (!msg->parseAttachment(STORE_ATTACH_LISTENER, listenerInfo)) {
    LOG(ERROR) << "store " << storeName << " is not found.";
    return;
  }

  uint32_t index = listenerInfo->listener_index();
  auto& listeners = config->getStoreListener();
  for (int32_t i = index; i < listeners.size(); ++ i) {
    StoreListener* listener = listeners[i];
    auto code = listener->insert(msg);
    switch (code) {
      case LRC_CONTINUE:
        continue;
      case LRC_BREAK:
      case LRC_END:
        break;
      case LRC_ERROR:
        LOG(ERROR) << "error when execute listener " << listener->getName() << ", index " << i;
        break;
    }
  }

  delete listenerInfo;
}