add simple dummy indexer

This commit is contained in:
kimchy 2010-09-07 18:19:02 +03:00
parent ad5945f141
commit e151b83372
4 changed files with 148 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import org.elasticsearch.common.collect.Lists;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index; import org.elasticsearch.index.Index;
import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indexer.IndexerName;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; 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])); 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<String> 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) { public static ESLogger getLogger(Class clazz, Settings settings, String... prefixes) {
return getLogger(getLoggerName(clazz), settings, prefixes); return getLogger(getLoggerName(clazz), settings, prefixes);
} }

View File

@ -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", "");
}
}

View File

@ -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);
}
}

View File

@ -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();
}
}