Example usage for org.apache.commons.collections.map LRUMap LRUMap

List of usage examples for org.apache.commons.collections.map LRUMap LRUMap

Introduction

In this page you can find the example usage for org.apache.commons.collections.map LRUMap LRUMap.

Prototype

public LRUMap(Map map) 

Source Link

Document

Constructor copying elements from another map.

Usage

From source file:org.zaproxy.zap.extension.sse.db.TableEventStream.java

/** Create tables if not already available */
@Override/*  ww  w  . j  a  v a 2 s  .c o  m*/
protected void reconnect(Connection conn) throws DatabaseException {
    try {
        if (!DbUtils.hasTable(conn, "EVENT_STREAM")) {
            // need to create the tables
            PreparedStatement stmt = conn.prepareStatement("CREATE CACHED TABLE event_stream ("
                    + "stream_id BIGINT PRIMARY KEY," + "host VARCHAR(255) NOT NULL," + "port INTEGER NOT NULL,"
                    + "url VARCHAR(255) NOT NULL," + "start_timestamp TIMESTAMP NOT NULL,"
                    + "end_timestamp TIMESTAMP NULL," + "history_id INTEGER NULL,"
                    + "FOREIGN KEY (history_id) REFERENCES HISTORY(HISTORYID) ON DELETE SET NULL ON UPDATE SET NULL"
                    + ")");
            DbUtils.executeAndClose(stmt);

            stmt = conn
                    .prepareStatement("CREATE CACHED TABLE event_stream_event (" + "event_id BIGINT NOT NULL,"
                            + "stream_id BIGINT NOT NULL," + "timestamp TIMESTAMP NOT NULL,"
                            + "last_event_id VARCHAR(255) NOT NULL," + "data CLOB(16M) NOT NULL,"
                            + "event_type VARCHAR(255) NOT NULL," + "reconnection_time BIGINT NULL,"
                            + "raw_event CLOB(16M) NOT NULL," + "PRIMARY KEY (event_id, stream_id),"
                            + "FOREIGN KEY (stream_id) REFERENCES event_stream(stream_id)" + ")");
            DbUtils.executeAndClose(stmt);

            streamIds = new HashSet<>();
        } else {
            streamIds = null;
        }

        streamCache = new LRUMap(20);

        // STREAMS
        psSelectMaxStreamId = conn
                .prepareStatement("SELECT MAX(s.stream_id) as stream_id " + "FROM event_stream AS s");

        psSelectStreams = conn
                .prepareStatement("SELECT s.* " + "FROM event_stream AS s " + "ORDER BY s.stream_id");

        // id goes last to be consistent with update query
        psInsertStream = conn.prepareStatement("INSERT INTO "
                + "event_stream (host, port, url, start_timestamp, end_timestamp, history_id, stream_id) "
                + "VALUES (?,?,?,?,?,?,?)");

        psUpdateStream = conn.prepareStatement("UPDATE event_stream SET "
                + "host = ?, port = ?, url = ?, start_timestamp = ?, end_timestamp = ?, history_id = ? "
                + "WHERE stream_id = ?");

        psUpdateHistoryFk = conn
                .prepareStatement("UPDATE event_stream SET " + "history_id = ? " + "WHERE stream_id = ?");

        psDeleteStream = conn.prepareStatement("DELETE FROM event_stream " + "WHERE stream_id = ?");

        // EVENTS
        psSelectEvent = conn.prepareStatement(
                "SELECT e.* " + "FROM event_stream_event AS e " + "WHERE e.event_id = ? AND e.stream_id = ?");

        psInsertEvent = conn.prepareStatement("INSERT INTO "
                + "event_stream_event (event_id, stream_id, timestamp, last_event_id, data, event_type, reconnection_time, raw_event) "
                + "VALUES (?,?,?,?,?,?,?,?)");

        psDeleteEventsByStreamId = conn
                .prepareStatement("DELETE FROM event_stream_event " + "WHERE stream_id = ?");

        if (streamIds == null) {
            streamIds = new HashSet<>();
            PreparedStatement psSelectStreamIds = conn.prepareStatement(
                    "SELECT s.stream_id " + "FROM event_stream AS s " + "ORDER BY s.stream_id");
            try {
                psSelectStreamIds.execute();

                ResultSet rs = psSelectStreamIds.getResultSet();
                while (rs.next()) {
                    streamIds.add(rs.getInt(1));
                }
            } finally {
                try {
                    psSelectStreamIds.close();
                } catch (SQLException e) {
                    if (logger.isDebugEnabled()) {
                        logger.debug(e.getMessage(), e);
                    }
                }
            }
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}

From source file:org.zaproxy.zap.extension.sse.ui.EventStreamViewModel.java

/**
 * Useful Ctor for subclasses./*from   w ww. jav  a  2  s  .  c  om*/
 *
 * @param databaseTable
 */
protected EventStreamViewModel(TableEventStream databaseTable) {
    super();

    table = databaseTable;
    fullMessagesCache = new LRUMap(10);
}

From source file:org.zaproxy.zap.extension.websocket.db.TableWebSocket.java

/** Create tables if not already available */
@Override//from   ww  w.  jav  a 2s.c  o m
protected void reconnect(Connection conn) throws DatabaseException {
    try {
        if (!DbUtils.hasTable(conn, "WEBSOCKET_CHANNEL")) {
            // need to create the tables
            DbUtils.execute(conn, "CREATE CACHED TABLE websocket_channel (" + "channel_id BIGINT PRIMARY KEY,"
                    + "host VARCHAR(255) NOT NULL," + "port INTEGER NOT NULL,"
                    + "url VARCHAR(1048576) NOT NULL," + "start_timestamp TIMESTAMP NOT NULL,"
                    + "end_timestamp TIMESTAMP NULL," + "history_id INTEGER NULL,"
                    + "FOREIGN KEY (history_id) REFERENCES HISTORY(HISTORYID) ON DELETE SET NULL ON UPDATE SET NULL"
                    + ")");

            DbUtils.execute(conn,
                    "CREATE CACHED TABLE websocket_message (" + "message_id BIGINT NOT NULL,"
                            + "channel_id BIGINT NOT NULL," + "timestamp TIMESTAMP NOT NULL,"
                            + "opcode TINYINT NOT NULL," + "payload_utf8 CLOB(16M) NULL,"
                            + "payload_bytes BLOB(16M) NULL," + "payload_length BIGINT NOT NULL,"
                            + "is_outgoing BOOLEAN NOT NULL," + "PRIMARY KEY (message_id, channel_id),"
                            + "FOREIGN KEY (channel_id) REFERENCES websocket_channel(channel_id)" + ")");

            DbUtils.execute(conn, "ALTER TABLE websocket_message " + "ADD CONSTRAINT websocket_message_payload "
                    + "CHECK (payload_utf8 IS NOT NULL OR payload_bytes IS NOT NULL)");

            DbUtils.execute(conn, "CREATE CACHED TABLE websocket_message_fuzz (" + "fuzz_id BIGINT NOT NULL,"
                    + "message_id BIGINT NOT NULL," + "channel_id BIGINT NOT NULL,"
                    + "state VARCHAR(50) NOT NULL," + "fuzz LONGVARCHAR NOT NULL,"
                    + "PRIMARY KEY (fuzz_id, message_id, channel_id),"
                    + "FOREIGN KEY (message_id, channel_id) REFERENCES websocket_message(message_id, channel_id) ON DELETE CASCADE"
                    + ")");

            channelIds = new HashSet<>();
        } else {
            channelIds = null;
        }

        channelCache = new LRUMap(20);

        // CHANNEL
        psSelectMaxChannelId = conn
                .prepareStatement("SELECT MAX(c.channel_id) as channel_id " + "FROM websocket_channel AS c");

        psSelectChannels = conn
                .prepareStatement("SELECT c.* " + "FROM websocket_channel AS c " + "ORDER BY c.channel_id");

        // id goes last to be consistent with update query
        psInsertChannel = conn.prepareStatement("INSERT INTO "
                + "websocket_channel (host, port, url, start_timestamp, end_timestamp, history_id, channel_id) "
                + "VALUES (?,?,?,?,?,?,?)");

        psUpdateChannel = conn.prepareStatement("UPDATE websocket_channel SET "
                + "host = ?, port = ?, url = ?, start_timestamp = ?, end_timestamp = ?, history_id = ? "
                + "WHERE channel_id = ?");

        psUpdateHistoryFk = conn
                .prepareStatement("UPDATE websocket_channel SET " + "history_id = ? " + "WHERE channel_id = ?");

        psDeleteChannel = conn.prepareStatement("DELETE FROM websocket_channel " + "WHERE channel_id = ?");

        // MESSAGE
        psSelectMessage = conn.prepareStatement("SELECT m.*, f.fuzz_id, f.state, f.fuzz "
                + "FROM websocket_message AS m " + "LEFT OUTER JOIN websocket_message_fuzz f "
                + "ON m.message_id = f.message_id AND m.channel_id = f.channel_id "
                + "WHERE m.message_id = ? AND m.channel_id = ?");

        psInsertMessage = conn.prepareStatement("INSERT INTO "
                + "websocket_message (message_id, channel_id, timestamp, opcode, payload_utf8, payload_bytes, payload_length, is_outgoing) "
                + "VALUES (?,?,?,?,?,?,?,?)");

        psInsertFuzz = conn.prepareStatement(
                "INSERT INTO " + "websocket_message_fuzz (fuzz_id, message_id, channel_id, state, fuzz) "
                        + "VALUES (?,?,?,?,?)");

        psDeleteMessagesByChannelId = conn
                .prepareStatement("DELETE FROM websocket_message " + "WHERE channel_id = ?");

        if (channelIds == null) {
            channelIds = new HashSet<>();
            PreparedStatement psSelectChannelIds = conn.prepareStatement(
                    "SELECT c.channel_id " + "FROM websocket_channel AS c " + "ORDER BY c.channel_id");
            try {
                psSelectChannelIds.execute();

                ResultSet rs = psSelectChannelIds.getResultSet();
                while (rs.next()) {
                    channelIds.add(rs.getInt(1));
                }
            } finally {
                try {
                    psSelectChannelIds.close();
                } catch (SQLException e) {
                    if (logger.isDebugEnabled()) {
                        logger.debug(e.getMessage(), e);
                    }
                }
            }
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}

From source file:org.zaproxy.zap.extension.websocket.ui.WebSocketMessagesViewModel.java

/** Useful Ctor for subclasses. */
protected WebSocketMessagesViewModel(TableWebSocket webSocketTable) {
    super();//w  w  w  .  j  a  va  2  s . c  o m

    table = webSocketTable;
    fullMessagesCache = new LRUMap(10);
}

From source file:phex.gui.tabs.library.FileSystemTableCellRenderer.java

public FileSystemTableCellRenderer() {
    fsv = FileSystemView.getFileSystemView();
    shareFileIconMap = new LRUMap(100);
    grayMap = new LRUMap(100);

    defaultIcon = GUIRegistry.getInstance().getPlafIconPack().getIcon("Library.File");
    defaultGrayIcon = ImageFilterUtils.createGrayIcon(defaultIcon);
}

From source file:pt.webdetails.cda.settings.SettingsManager.java

/**
 * This class controls how the different .cda files will be read
 * and cached./* w w  w  .j  a v a  2 s.com*/
 */
public SettingsManager() {

    // TODO - Read the cache size from disk. Eventually move to ehcache, if necessary

    logger.debug("Initializing SettingsManager.");

    settingsCache = new LRUMap(MAX_SETTINGS_CACHE_SIZE);
    settingsTimestamps = new HashMap<String, Long>();

    this.defaultResourceLoader = new CdaRepositoryResourceLoader(DEFAULT_RESOURCE_LOADER_NAME);
    // order is important
    this.resourceLoaders = new LinkedHashMap<String, ICdaResourceLoader>();
    this.resourceLoaders.put(DEFAULT_RESOURCE_LOADER_NAME, defaultResourceLoader);
    this.resourceLoaders.put(SYSTEM_RESOURCE_LOADER_NAME,
            new CdaSystemResourceLoader(SYSTEM_RESOURCE_LOADER_NAME));
}

From source file:uk.ac.ebi.intact.dataexchange.psimi.solr.ontology.OntologySearcher.java

public OntologySearcher(SolrServer solrServer) {
    if (solrServer == null) {
        throw new IllegalArgumentException("You must give a non null solrServer");
    }/* w  ww  .  j a v a 2 s . c  o m*/

    this.solrServer = solrServer;

    childSearchesMap = new LRUMap(CHILDREN_CACHE_SIZE);
    parentSearchesMap = new LRUMap(PARENTS_CACHE_SIZE);
    synonymsSearchesMap = new LRUMap(PARENTS_CACHE_SIZE);
}