org.hpccsystems.ws.client.utils.DataSingletonCollection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wsclient Show documentation
Show all versions of wsclient Show documentation
This project allows a user to interact with ESP services in a controlled manner. The API calls available under org.hpccsystems.ws.client.platform allow for a user to target ESP's across multiple environments running a range of hpccsystems-platform versions. There is no guarantee that if a user utilizes org.hpccsystems.ws.client.gen generated stub code from wsdl, that the calls will be backwards compatible with older hpccsystems-platform versions.
/*******************************************************************************
* Copyright (c) 2014 HPCC Systems. All rights reserved. This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors: HPCC Systems - initial API and implementation
******************************************************************************/
package org.hpccsystems.ws.client.utils;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Observable;
public class DataSingletonCollection extends Observable
{
Map items;
CollectionDelta notificationDelta;
int notifcationDepth;
public DataSingletonCollection()
{
items = new HashMap();
notificationDelta = null;
notifcationDepth = 0;
}
public synchronized DataSingleton get(DataSingleton item)
{
if (items.containsKey(item.hashCode()))
{
return items.get(item.hashCode());
}
else
{
try
{
pushTransaction("DataSingletonCollection.get");
items.put(item.hashCode(), item);
setChanged();
}
finally
{
popTransaction();
}
}
return item;
}
public synchronized DataSingleton getNoCreate(DataSingleton item)
{
if (items.containsKey(item.hashCode()))
{
return items.get(item.hashCode());
}
return null;
}
public synchronized void remove(DataSingleton item)
{
if (items.containsKey(item.hashCode()))
{
items.remove(item);
}
}
public synchronized Collection getAll()
{
return items.values();
}
public synchronized void pushTransaction(String cause)
{
if (notifcationDepth == 0)
{
notificationDelta = new CollectionDelta(cause, items.values());
}
++notifcationDepth;
}
public synchronized void popTransaction()
{
--notifcationDepth;
if (notifcationDepth == 0)
{
notifyObservers(notificationDelta.calcChanges(items.values()));
notificationDelta = null;
}
}
public synchronized void clear()
{
items.clear();
setChanged();
}
}