001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.reef.io.storage.ram; 020 021import org.apache.reef.io.ExternalMap; 022import org.apache.reef.io.storage.util.GetAllIterable; 023 024import javax.inject.Inject; 025import java.util.Map; 026import java.util.Map.Entry; 027import java.util.Set; 028import java.util.concurrent.ConcurrentSkipListMap; 029 030/** 031 * Simple in-memory ExternalMap implementation. This class does not require 032 * any codecs, and so is guaranteed to be instantiable. Therefore, it is the 033 * default ExternalMap provided by StorageManagerRam. 034 */ 035public class RamMap<T> implements ExternalMap<T> { 036 private final ConcurrentSkipListMap<CharSequence, T> map 037 = new ConcurrentSkipListMap<CharSequence, T>(); 038 039 @Inject 040 public RamMap(RamStorageService ramStore) { 041 //this.localStore = localStore; 042 } 043 044 @Override 045 public boolean containsKey(CharSequence key) { 046 return map.containsKey(key); 047 } 048 049 @Override 050 public T get(CharSequence key) { 051 return map.get(key); 052 } 053 054 @Override 055 public T put(CharSequence key, T value) { 056 return map.put(key, value); 057 } 058 059 @Override 060 public T remove(CharSequence key) { 061 return map.remove(key); 062 } 063 064 @Override 065 public void putAll(Map<? extends CharSequence, ? extends T> m) { 066 map.putAll(m); 067 } 068 069 @Override 070 public Iterable<Entry<CharSequence, T>> getAll(Set<? extends CharSequence> keys) { 071 return new GetAllIterable<>(keys, this); 072 } 073 074}