All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.zeebe.logstreams.impl.service.LogBlockIndexService Maven / Gradle / Ivy

There is a newer version: 0.16.4
Show newest version
/*
 * Copyright © 2017 camunda services GmbH ([email protected])
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */
package io.zeebe.logstreams.impl.service;

import static io.zeebe.logstreams.impl.LogBlockIndexWriter.LOG;

import io.zeebe.db.ZeebeDbFactory;
import io.zeebe.db.impl.rocksdb.ZeebeRocksDbFactory;
import io.zeebe.logstreams.impl.log.index.LogBlockColumnFamilies;
import io.zeebe.logstreams.impl.log.index.LogBlockIndex;
import io.zeebe.logstreams.state.StateStorage;
import io.zeebe.servicecontainer.Service;
import io.zeebe.servicecontainer.ServiceStartContext;
import io.zeebe.servicecontainer.ServiceStopContext;

public class LogBlockIndexService implements Service {
  private LogBlockIndex logBlockIndex;
  private final StateStorage stateStorage;

  public LogBlockIndexService(StateStorage stateStorage) {
    this.stateStorage = stateStorage;
  }

  @Override
  public void start(ServiceStartContext startContext) {
    final ZeebeDbFactory dbFactory =
        ZeebeRocksDbFactory.newFactory(LogBlockColumnFamilies.class);

    logBlockIndex = new LogBlockIndex(dbFactory, stateStorage);
  }

  @Override
  public void stop(ServiceStopContext stopContext) {
    try {
      logBlockIndex.closeDb();
    } catch (Exception e) {
      LOG.error("Couldn't close block index db", e);
    }
    logBlockIndex = null;
  }

  @Override
  public LogBlockIndex get() {
    return logBlockIndex;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy