incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject git commit: Rename server class.
Date Sun, 07 Oct 2012 14:21:44 GMT
Updated Branches:
  refs/heads/new-api-prototype 2c4dc79f1 -> 06df22a65


Rename server class.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/06df22a6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/06df22a6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/06df22a6

Branch: refs/heads/new-api-prototype
Commit: 06df22a65eeaf1d4abe7abb755884fffa6d8039a
Parents: 2c4dc79
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Sun Oct 7 10:21:09 2012 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Sun Oct 7 10:21:09 2012 -0400

----------------------------------------------------------------------
 .../main/java/org/apache/blur/core/HDFSServer.java |  269 ---------------
 1 files changed, 0 insertions(+), 269 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/06df22a6/src/blur-new-api-prototype/src/main/java/org/apache/blur/core/HDFSServer.java
----------------------------------------------------------------------
diff --git a/src/blur-new-api-prototype/src/main/java/org/apache/blur/core/HDFSServer.java
b/src/blur-new-api-prototype/src/main/java/org/apache/blur/core/HDFSServer.java
deleted file mode 100644
index 2144946..0000000
--- a/src/blur-new-api-prototype/src/main/java/org/apache/blur/core/HDFSServer.java
+++ /dev/null
@@ -1,269 +0,0 @@
-package org.apache.blur.core;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF 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.
- */
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.blur.store.SimpleHDFSDirectory;
-import org.apache.blur.thrift.generated.Attribute;
-import org.apache.blur.thrift.generated.BlurException;
-import org.apache.blur.thrift.generated.BlurTuple.Iface;
-import org.apache.blur.thrift.generated.BlurTuple.Processor;
-import org.apache.blur.thrift.generated.Session;
-import org.apache.blur.thrift.generated.Tuple;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.Path;
-import org.apache.lucene.analysis.core.KeywordAnalyzer;
-import org.apache.lucene.codecs.appending.AppendingCodec;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.index.DirectoryReader;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
-import org.apache.lucene.index.IndexableField;
-import org.apache.lucene.queryparser.classic.QueryParser;
-import org.apache.lucene.search.MatchAllDocsQuery;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.Version;
-import org.apache.thrift.TException;
-import org.apache.thrift.protocol.TBinaryProtocol;
-import org.apache.thrift.server.TThreadPoolServer;
-import org.apache.thrift.server.TThreadPoolServer.Args;
-import org.apache.thrift.transport.TFramedTransport;
-import org.apache.thrift.transport.TServerSocket;
-import org.apache.thrift.transport.TTransportException;
-
-public class HDFSServer implements Iface {
-
-  private static final List<Tuple> EMPTY_LIST = new ArrayList<Tuple>();
-
-  public static void main(String[] argsStr) throws TTransportException, IOException {
-    Configuration conf = new Configuration();
-    HDFSServer server = new HDFSServer(conf, new Path(argsStr[0]));
-    Processor<Iface> processor = new Processor<Iface>(server);
-    Args args = new Args(new TServerSocket(new InetSocketAddress("127.0.0.1", 9000)));
-    args.minWorkerThreads(50);
-    args.maxWorkerThreads(50);
-    args.processor(processor);
-    args.transportFactory(new TFramedTransport.Factory());
-    args.protocolFactory(new TBinaryProtocol.Factory(true, true));
-
-    TThreadPoolServer tserver = new TThreadPoolServer(args);
-    tserver.serve();
-  }
-
-  private Map<String, RSession> readSessions = new ConcurrentHashMap<String, RSession>();
-  private Map<String, WSession> writeSessions = new ConcurrentHashMap<String, WSession>();
-  private IndexWriter writer;
-  private Path path;
-  private Configuration configuration;
-
-  public HDFSServer(Configuration configuration, Path path) throws IOException {
-    this.path = path;
-    this.configuration = configuration;
-    Directory directory = new SimpleHDFSDirectory(configuration, path);
-    this.writer = openWriter(directory);
-  }
-
-  private IndexWriter openWriter(Directory directory) throws IOException {
-    IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_40, new KeywordAnalyzer());
-    conf.setCodec(new AppendingCodec());
-    return new IndexWriter(directory, conf);
-  }
-
-  @Override
-  public Session openReadSession() throws BlurException, TException {
-    try {
-      IndexReader reader = DirectoryReader.open(writer, true);
-      RSession session = new RSession(UUID.randomUUID().toString(), reader);
-      readSessions.put(session.getSessionId(), session);
-      return new Session(session.getSessionId());
-    } catch (Throwable t) {
-      throw Util.wrapThrowable(t);
-    }
-  }
-
-  @Override
-  public void executeQuery(Session readSession, String query) throws BlurException, TException
{
-    try {
-      RSession session = getReadSession(readSession);
-      if (query.trim().equals("*")) {
-        session.execute(new MatchAllDocsQuery());
-        return;
-      }
-      QueryParser parser = new QueryParser(Version.LUCENE_40, "SUPER", new KeywordAnalyzer());
-      parser.setAllowLeadingWildcard(true);
-      session.execute(parser.parse(query));
-    } catch (Throwable t) {
-      throw Util.wrapThrowable(t);
-    }
-  }
-
-  @Override
-  public List<Tuple> nextMetaDataResults(Session readSession, int batchSize) throws
BlurException, TException {
-    try {
-      RSession session = getReadSession(readSession);
-      if (session.isMetaDataBeenFetched()) {
-        return EMPTY_LIST;
-      }
-      Tuple tuple = new Tuple();
-      tuple.addToAttributes(Util.newAttribute("totalResults", session.getTotalHits()));
-      return Arrays.asList(tuple);
-    } catch (Throwable t) {
-      throw Util.wrapThrowable(t);
-    }
-  }
-
-  @Override
-  public List<Tuple> nextResults(Session readSession, int batchSize) throws BlurException,
TException {
-    try {
-      RSession session = getReadSession(readSession);
-      List<Tuple> results = new ArrayList<Tuple>();
-      for (int i = 0; i < batchSize; i++) {
-        Tuple tuple = convert(session.nextDocument());
-        if (tuple == null) {
-          break;
-        }
-        results.add(tuple);
-      }
-      return results;
-    } catch (Throwable t) {
-      throw Util.wrapThrowable(t);
-    }
-  }
-
-  @Override
-  public void closeReadSession(Session readSession) throws BlurException, TException {
-    try {
-      RSession session = readSessions.remove(readSession.getSessionId());
-      session.close();
-    } catch (Throwable t) {
-      throw Util.wrapThrowable(t);
-    }
-  }
-
-  @Override
-  public Session openWriteSession() throws BlurException, TException {
-    try {
-      String id = UUID.randomUUID().toString();
-      Path p = new Path(path, id);
-      Directory directory = new SimpleHDFSDirectory(configuration, p);
-      WSession session = new WSessionThreadedPath(id, openWriter(directory), directory, p);
-      writeSessions.put(session.getSessionId(), session);
-      return new Session(session.getSessionId());
-    } catch (Throwable t) {
-      throw Util.wrapThrowable(t);
-    }
-  }
-
-  @Override
-  public void writeTuples(Session writeSession, List<Tuple> tuples) throws BlurException,
TException {
-    try {
-      WSession session = getWriteSession(writeSession);
-      session.addDocuments(convert(tuples));
-    } catch (Throwable t) {
-      throw Util.wrapThrowable(t);
-    }
-  }
-
-  @Override
-  public void commitWriteSession(Session writeSession) throws BlurException, TException {
-    try {
-      WSession session = writeSessions.remove(writeSession.getSessionId());
-      session.closeWriter();
-      writer.addIndexes(session.getDirectory());
-      writer.commit();
-      writer.maybeMerge();
-      rm(((WSessionThreadedPath) session).getPath());
-    } catch (Throwable t) {
-      throw Util.wrapThrowable(t);
-    }
-  }
-
-  @Override
-  public void rollbackWriteSession(Session writeSession) throws BlurException, TException
{
-    try {
-      WSession session = writeSessions.remove(writeSession.getSessionId());
-      session.closeWriter();
-      rm(((WSessionThreadedPath) session).getPath());
-    } catch (Throwable t) {
-      throw Util.wrapThrowable(t);
-    }
-  }
-
-  private void rm(Path path) throws IOException {
-    FileSystem fileSystem = path.getFileSystem(configuration);
-    fileSystem.delete(path, true);
-    fileSystem.close();
-  }
-
-  private Document convert(Tuple tuple) throws BlurException {
-    if (tuple == null) {
-      return null;
-    }
-    Document newDoc = new Document();
-    for (Attribute attribute : tuple.getAttributes()) {
-      newDoc.add(Util.getField(attribute));
-    }
-    return newDoc;
-  }
-
-  private Tuple convert(Document document) {
-    if (document == null) {
-      return null;
-    }
-    List<IndexableField> fields = document.getFields();
-    Tuple tuple = new Tuple();
-    for (IndexableField fieldable : fields) {
-      tuple.addToAttributes(Util.toAttribute(fieldable));
-    }
-    return tuple;
-  }
-
-  private List<Document> convert(List<Tuple> tuples) throws BlurException {
-    List<Document> docs = new ArrayList<Document>();
-    for (Tuple tuple : tuples) {
-      docs.add(convert(tuple));
-    }
-    return docs;
-  }
-
-  private WSession getWriteSession(Session session) throws BlurException {
-    WSession wsession = writeSessions.get(session.getSessionId());
-    if (wsession == null) {
-      throw new BlurException("Write Session [" + session + "] not found", null);
-    }
-    return wsession;
-  }
-
-  private RSession getReadSession(Session session) throws BlurException {
-    RSession rsession = readSessions.get(session.getSessionId());
-    if (rsession == null) {
-      throw new BlurException("Read Session [" + session + "] not found", null);
-    }
-    return rsession;
-  }
-
-}


Mime
View raw message