class FileIndexerQueueListener implements MessageListener {

    @Override
    public void onMessage(final Message message) {
        if (message instanceof ObjectMessage) {
            ObjectMessage objectMessage = (ObjectMessage) message;
            try {
                IndexMessage indexMessage = (IndexMessage) objectMessage.getObject();
                String fileName = indexMessage.getFileName();
                String type = indexMessage.getType();
                if (type.equals(IndexingType.ADD.getName())) {
                    luceneEngine.addFileToIndex(fileName);
                } else if (type.equals(IndexingType.DELETE.getName())) {
                    luceneEngine.deleteFileFromIndex(fileName);
                }
            } catch (JMSException e) {
                throw new SystemException("Message information transfer failed. Reason:" + e.getMessage());
            } catch (OutOfMemoryError e) {
                logger.error("HeapMaxMemory:" + Runtime.getRuntime().maxMemory() + ", HeapTotalMemory:" + Runtime.getRuntime().totalMemory()
                        + ", HeapFreeMemory:" + Runtime.getRuntime().freeMemory() + ", Exception: ", e);
                shutdown();
            }

        }
    }

}