// $Id$
//
// 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.
//
using System;
using System.Collections.Generic;
using org.apache.etch.examples.distmap.types.DistributedHashTable;
namespace org.apache.etch.examples.distmap
{
///Implementation for ImplDistributedHashTableServer
public class ImplDistributedHashTableServer : BaseDistributedHashTableServer
{
/// Constructs the ImplDistributedHashTableServer.
/// a connection to the client session. Use this to
/// send a message to the client.
///
public ImplDistributedHashTableServer(RemoteDistributedHashTableClient client, IDictionary map)
{
this.map = map;
}
private IDictionary map;
///
/// Gets all elements in DHT
///
/// An array of entries
public override Entry[] getAll()
{
lock (map)
{
Entry[] list = new Entry[map.Count];
int index = 0;
foreach (string str in map.Keys)
{
list[index++] = new Entry(str, map[str]);
}
return list;
}
}
///
/// Gets an object from DHT
///
///
///
public override object getObject(string key)
{
object value;
if (!map.TryGetValue(key, out value))
{
Console.WriteLine(" {0} not found in DHT ", key);
}
return value;
}
///
/// Puts object in Map
///
///
///
///
public override object putObject(string key, object value)
{
map.Add(key, value);
return value;
}
///
/// Removes Object from DHT
///
///
///
public override object removeObject(string key)
{
map.Remove(key);
return null;
}
///
/// Gets Size of DHT
///
///
public override int? size()
{
return map.Count;
}
}
}