alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

ActiveMQ example source code file (VMIndex.java)

This example ActiveMQ source code file (VMIndex.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - ActiveMQ tags/keywords

failed, failed, index, indexmanager, indexmbean, io, ioexception, ioexception, logger, map, runtimeexception, storeentry, storeentry, util, vmindex, vmindex

The ActiveMQ VMIndex.java source code

/**
 * 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.
 */
package org.apache.activemq.kaha.impl.index;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.activemq.kaha.IndexMBean;
import org.apache.activemq.kaha.Marshaller;
import org.apache.activemq.kaha.StoreEntry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Index implementation using a HashMap
 *
 * 
 */
public class VMIndex implements Index, IndexMBean {
    private static final Logger LOG = LoggerFactory.getLogger(VMIndex.class);
    private IndexManager indexManager;
    private Map<Object, StoreEntry> map = new HashMap();

    public VMIndex(IndexManager manager) {
        this.indexManager = manager;
    }

    /**
     *
     * @see org.apache.activemq.kaha.impl.index.Index#clear()
     */
    public void clear() {
        map.clear();
    }

    /**
     * @param key
     * @return true if the index contains the key
     * @see org.apache.activemq.kaha.impl.index.Index#containsKey(java.lang.Object)
     */
    public boolean containsKey(Object key) {
        return map.containsKey(key);
    }

    /**
     * @param key
     * @return store entry
     * @see org.apache.activemq.kaha.impl.index.Index#removeKey(java.lang.Object)
     */
    public StoreEntry remove(Object key) {
        StoreEntry result = map.remove(key);
        if (result != null) {
            try {
                result = indexManager.refreshIndex((IndexItem)result);
            } catch (IOException e) {
                LOG.error("Failed to refresh entry", e);
                throw new RuntimeException("Failed to refresh entry");
            }
        }
        return result;
    }

    /**
     * @param key
     * @param entry
     * @see org.apache.activemq.kaha.impl.index.Index#store(java.lang.Object,
     *      org.apache.activemq.kaha.impl.index.IndexItem)
     */
    public void store(Object key, StoreEntry entry) {
        map.put(key, entry);
    }

    /**
     * @param key
     * @return the entry
     */
    public StoreEntry get(Object key) {
        StoreEntry result = map.get(key);
        if (result != null) {
            try {
                result = indexManager.refreshIndex((IndexItem)result);
            } catch (IOException e) {
                LOG.error("Failed to refresh entry", e);
                throw new RuntimeException("Failed to refresh entry");
            }
        }
        return result;
    }

    /**
     * @return true if the index is transient
     */
    public boolean isTransient() {
        return true;
    }

    /**
     * load indexes
     */
    public void load() {
    }

    /**
     * unload indexes
     */
    public void unload() {
        map.clear();
    }

    public void delete() throws IOException {
        unload();
    }

    public void setKeyMarshaller(Marshaller marshaller) {
    }

    public int getSize() {
        return map.size();
    }
}

Other ActiveMQ examples (source code examples)

Here is a short list of links related to this ActiveMQ VMIndex.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.