/* MockP2PServer.java * * Copyright (c) 2003, Benja Fallenstein * * This file is part of Storm. * * Storm is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Storm is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General * Public License for more details. * * You should have received a copy of the GNU Lesser General * Public License along with Storm; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * */ /* * Written by Benja Fallenstein */ package org.nongnu.storm.impl.p2p; import org.nongnu.storm.*; import org.nongnu.storm.impl.*; import java.io.*; import java.util.*; public class MockP2PServer implements P2PPool.Server { protected static Map servers = new HashMap(); protected String id; protected StormPool pool; public MockP2PServer() { id = ""+hashCode(); servers.put(id, this); } public void setPool(StormPool pool) { if(this.pool != null) throw new IllegalStateException("Pool already set"); this.pool = pool; } public String getURL(BlockId blockId) { return id + "//" + blockId.getURI(); } public InputStream download(String url) throws IOException { int i = url.indexOf("//"); String serverId = url.substring(0, i); BlockId blockId = new BlockId(url.substring(i+2)); MockP2PServer server = (MockP2PServer)servers.get(serverId); return server.pool.get(blockId).getInputStream(); } }