From e151b833728fdd7c44f4fd063462fb0a161b97d1 Mon Sep 17 00:00:00 2001 From: kimchy Date: Tue, 7 Sep 2010 18:19:02 +0300 Subject: [PATCH] add simple dummy indexer --- .../elasticsearch/common/logging/Loggers.java | 10 +++ .../indexer/AbstractIndexerComponent.java | 63 +++++++++++++++++++ .../indexer/dummy/DummyIndexer.java | 42 +++++++++++++ .../indexer/dummy/DummyIndexerModule.java | 33 ++++++++++ 4 files changed, 148 insertions(+) create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/indexer/AbstractIndexerComponent.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/indexer/dummy/DummyIndexer.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/indexer/dummy/DummyIndexerModule.java diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/Loggers.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/Loggers.java index 73744c8d4f1..74a5a3d518f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/Loggers.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/Loggers.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.collect.Lists; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.indexer.IndexerName; import java.net.InetAddress; import java.net.UnknownHostException; @@ -63,6 +64,15 @@ public class Loggers { return getLogger(clazz, settings, Lists.asList(SPACE, index.name(), prefixes).toArray(new String[0])); } + public static ESLogger getLogger(Class clazz, Settings settings, IndexerName indexerName, String... prefixes) { + List l = Lists.newArrayList(); + l.add(SPACE); + l.add(indexerName.type()); + l.add(indexerName.name()); + l.addAll(Lists.newArrayList(prefixes)); + return getLogger(clazz, settings, l.toArray(new String[l.size()])); + } + public static ESLogger getLogger(Class clazz, Settings settings, String... prefixes) { return getLogger(getLoggerName(clazz), settings, prefixes); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indexer/AbstractIndexerComponent.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indexer/AbstractIndexerComponent.java new file mode 100644 index 00000000000..e4c9b6f68ea --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indexer/AbstractIndexerComponent.java @@ -0,0 +1,63 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you 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 org.elasticsearch.indexer; + +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.indexer.settings.IndexerSettings; + +/** + * @author kimchy (shay.banon) + */ +public class AbstractIndexerComponent implements IndexerComponent { + + protected final ESLogger logger; + + protected final IndexerName indexerName; + + protected final Settings indexSettings; + + protected final Settings componentSettings; + + protected AbstractIndexerComponent(IndexerName indexerName, @IndexerSettings Settings indexSettings) { + this.indexerName = indexerName; + this.indexSettings = indexSettings; + this.componentSettings = indexSettings.getComponentSettings(getClass()); + + this.logger = Loggers.getLogger(getClass(), indexSettings, indexerName); + } + + protected AbstractIndexerComponent(IndexerName indexerName, @IndexerSettings Settings indexSettings, String prefixSettings) { + this.indexerName = indexerName; + this.indexSettings = indexSettings; + this.componentSettings = indexSettings.getComponentSettings(prefixSettings, getClass()); + + this.logger = Loggers.getLogger(getClass(), indexSettings, indexerName); + } + + @Override public IndexerName indexerName() { + return indexerName; + } + + public String nodeName() { + return indexSettings.get("name", ""); + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indexer/dummy/DummyIndexer.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indexer/dummy/DummyIndexer.java new file mode 100644 index 00000000000..bcfd3a4d60a --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indexer/dummy/DummyIndexer.java @@ -0,0 +1,42 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you 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 org.elasticsearch.indexer.dummy; + +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.indexer.AbstractIndexerComponent; +import org.elasticsearch.indexer.Indexer; +import org.elasticsearch.indexer.IndexerName; +import org.elasticsearch.indexer.settings.IndexerSettings; + +/** + * @author kimchy (shay.banon) + */ +public class DummyIndexer extends AbstractIndexerComponent implements Indexer { + + @Inject public DummyIndexer(IndexerName indexerName, @IndexerSettings Settings indexSettings) { + super(indexerName, indexSettings); + logger.info("created"); + } + + @Override public void close(boolean delete) { + logger.info("delete, actual_delete [{}]", delete); + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indexer/dummy/DummyIndexerModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indexer/dummy/DummyIndexerModule.java new file mode 100644 index 00000000000..25ef6f8f213 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indexer/dummy/DummyIndexerModule.java @@ -0,0 +1,33 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you 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 org.elasticsearch.indexer.dummy; + +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.indexer.Indexer; + +/** + * @author kimchy (shay.banon) + */ +public class DummyIndexerModule extends AbstractModule { + + @Override protected void configure() { + bind(Indexer.class).to(DummyIndexer.class).asEagerSingleton(); + } +}