A not yet finished but already readable Java Class.
package org.nanotek.mq.receive; |
import org.nanotek.Kong; |
import org.nanotek.cms.domain.lucene.Index; |
import org.nanotek.cms.domain.message.MessageType; |
import org.nanotek.lucene.index.manage.LuceneIndexWriteService; |
import org.nanotek.mq.MessageException; |
import org.nanotek.mq.Receiver; |
import org.nanotek.mq.ReceiverService; |
import org.nanotek.util.Base; |
//import org.springframework.jms.listener.DefaultMessageListenerContainer; |
import org.springframework.amqp.core.Message; |
import org.springframework.amqp.core.MessageProperties; |
import org.springframework.beans.BeansException; |
import org.springframework.context.ApplicationContext; |
import org.springframework.context.ApplicationContextAware; |
//T extends MessageType |
public class MetaIndexerReceiverService implements ReceiverService <Base<Kong<String>>,Message,MessageProperties>, ApplicationContextAware { |
private ApplicationContext context; |
LuceneIndexWriteService<Base<?>> indexWriteService; |
public MetaIndexerReceiverService() { |
} |
@Override |
public void setApplicationContext(ApplicationContext context) |
throws BeansException { |
this.context = context; |
} |
@Override |
public void processMessage(Base<Kong<String>> messageType, |
Message bodyMessage) { |
MessageProperties parameters = (MessageProperties) context.getBean("defaultReceiverParameter"); |
processMessage (messageType , bodyMessage , parameters); |
} |
@Override |
public void processMessage(Base<Kong<String>> messageType, |
Message bodyMessage, MessageProperties parameters) { now what...// processMessage(MessageTransformer.getMessage(bodyMessage)); |
} |
public void processMessage(MessageType messageType, |
Base<?> bodyMessage) throws MessageException { |
try{ |
switch(messageType) { |
case IndexCreate: |
System.err.println("INDEX REQUEST CREATE INDEX"); |
createIndex(bodyMessage); |
break; |
case IndexDelete: |
System.err.println("INDEX REQUEST DELETE NOT YET IMPLEMENTED"); |
case DocumentCreate: |
System.err.println("INDEX REQUEST DOCUMENT CREATED"); |
addDocument(bodyMessage); |
break; |
case IndexClose: |
System.err.println("INDEX REQUEST DOCUMENT CREATED"); |
closeIndex(bodyMessage); |
break; |
default: |
break; |
} |
}catch(Exception ex){ |
throw new MessageException(ex); |
} |
} |
private void closeIndex(Base<?> bodyMessage) { |
indexWriteService.shutDownService(); |
} |
private void addDocument(Base<?> bodyMessage) { |
if (indexWriteService.getStarted() == true) |
indexWriteService.indexDocument(bodyMessage); |
else |
throw new MessageException("Service NOT YET STARTED"); |
} |
private void createIndex(Base<?> bodyMessage) { |
Index index = (Index) bodyMessage; |
// if (indexWriteService.getStarted() == false) |
indexWriteService.initService(index); |
// else |
// indexWriteService.createIndexWriter(index); |
} |
public LuceneIndexWriteService<?> getIndexWriteService() { |
return indexWriteService; |
} |
public void setIndexWriteService(LuceneIndexWriteService<?> indexWriteService) { |
this.indexWriteService = (LuceneIndexWriteService<Base<?>>) indexWriteService; |
} |
} |