All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hpccsystems.ws.client.utils.DataSingletonCollection Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 9.8.20-1
Show newest version
/*******************************************************************************
 * 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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy