<commit_before>/*
 * JBoss, Home of Professional Open Source
 * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @author tags. All rights reserved.
 * See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU Lesser General Public License, v. 2.1.
 * This program is distributed in the hope that it will be useful, but WITHOUT A
 * 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,
 * v.2.1 along with this distribution; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA  02110-1301, USA.
 */
package org.jboss.as.console.client.domain.model.impl;

import com.google.gwt.user.client.rpc.AsyncCallback;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.domain.events.StaleModelEvent;
import org.jboss.as.console.client.domain.model.HostInformationStore;
import org.jboss.as.console.client.domain.model.Server;
import org.jboss.as.console.client.domain.model.ServerInstance;
import org.jboss.as.console.client.domain.model.SimpleCallback;
import org.jboss.as.console.client.domain.topology.HostInfo;
import org.jboss.dmr.client.dispatch.AsyncCommand;
import org.jboss.as.console.client.shared.schedule.LongRunningTask;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static org.jboss.as.console.client.domain.model.impl.LifecycleOperation.RESTART;
import static org.jboss.as.console.client.domain.model.impl.LifecycleOperation.START;

/**
 * @author <NAME>
 * @date 10/23/2012
 */
public class ServerGroupLifecycleCallback extends SimpleCallback<Boolean>
{
    int servers;
    private final Map<HostInfo, List<ServerInstance>> serversPerHost;
    private final LifecycleOperation lifecycleOp;
    private final HostInformationStore hostInfoStore;
    private final SimpleCallback<List<Server>> callback;

    public ServerGroupLifecycleCallback(final HostInformationStore hostInfoStore,
                                        final Map<HostInfo, List<ServerInstance>> serversPerHost,
                                        final LifecycleOperation lifecycleOp, final SimpleCallback<List<Server>> callback)
    {
        this.hostInfoStore = hostInfoStore;
        this.serversPerHost = serversPerHost;
        this.lifecycleOp = lifecycleOp;
        this.callback = callback;

        this.servers = 0;
        for (List<ServerInstance> serverInstances : serversPerHost.values())
        {
            servers += serverInstances.size();
        }
    }


    @Override
    public void onSuccess(final Boolean wasSuccessful)
    {
        if (wasSuccessful)
        {
            LongRunningTask poll = new LongRunningTask(new AsyncCommand<Boolean>()
            {
                @Override
                public void execute(final AsyncCallback<Boolean> callback)
                {
                    final List<Server> finishedServers = new ArrayList<Server>();

                    for (Map.Entry<HostInfo, List<ServerInstance>> entry : serversPerHost
                            .entrySet())
                    {
                        HostInfo hostInfo = entry.getKey();
                        List<ServerInstance> serverInstances = entry.getValue();
                        for (ServerInstance serverInstance : serverInstances)
                        {
                            hostInfoStore.getServerConfiguration(hostInfo.getName(), serverInstance.getServer(),
                                    new SimpleCallback<Server>()
                                    {
                                        @Override
                                        public void onSuccess(final Server server)
                                        {
                                            finishedServers.add(server);
                                            boolean keepPolling = lifecycleOp == START || lifecycleOp == RESTART ? !server
                                                    .isStarted() : server.isStarted();
                                            if (!keepPolling && finishedServers.size() == servers)
                                            {
                                                ServerGroupLifecycleCallback.this.callback.onSuccess(finishedServers);
                                                Console.MODULES.getEventBus().fireEvent(
                                                        new StaleModelEvent(StaleModelEvent.SERVER_GROUPS)
                                                );
                                            }
                                            callback.onSuccess(keepPolling);
                                        }
                                    });
                        }
                    }
                }
            }, lifecycleOp.limit());
            poll.schedule(500);
        }
    }<commit_msg>Fire stale model event when group operations are used<commit_after>/*
 * JBoss, Home of Professional Open Source
 * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @author tags. All rights reserved.
 * See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU Lesser General Public License, v. 2.1.
 * This program is distributed in the hope that it will be useful, but WITHOUT A
 * 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,
 * v.2.1 along with this distribution; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA  02110-1301, USA.
 */
package org.jboss.as.console.client.domain.model.impl;

import com.google.gwt.user.client.rpc.AsyncCallback;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.domain.events.StaleModelEvent;
import org.jboss.as.console.client.domain.model.HostInformationStore;
import org.jboss.as.console.client.domain.model.Server;
import org.jboss.as.console.client.domain.model.ServerInstance;
import org.jboss.as.console.client.domain.model.SimpleCallback;
import org.jboss.as.console.client.domain.topology.HostInfo;
import org.jboss.dmr.client.dispatch.AsyncCommand;
import org.jboss.as.console.client.shared.schedule.LongRunningTask;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static org.jboss.as.console.client.domain.model.impl.LifecycleOperation.RESTART;
import static org.jboss.as.console.client.domain.model.impl.LifecycleOperation.START;

/**
 * @author <NAME>
 * @date 10/23/2012
 */
public class ServerGroupLifecycleCallback extends SimpleCallback<Boolean>
{
    int servers;
    private final Map<HostInfo, List<ServerInstance>> serversPerHost;
    private final LifecycleOperation lifecycleOp;
    private final HostInformationStore hostInfoStore;
    private final SimpleCallback<List<Server>> callback;

    public ServerGroupLifecycleCallback(final HostInformationStore hostInfoStore,
                                        final Map<HostInfo, List<ServerInstance>> serversPerHost,
                                        final LifecycleOperation lifecycleOp, final SimpleCallback<List<Server>> callback)
    {
        this.hostInfoStore = hostInfoStore;
        this.serversPerHost = serversPerHost;
        this.lifecycleOp = lifecycleOp;
        this.callback = callback;

        this.servers = 0;
        for (List<ServerInstance> serverInstances : serversPerHost.values())
        {
            servers += serverInstances.size();
        }
    }


    @Override
    public void onSuccess(final Boolean wasSuccessful)
    {
        if (wasSuccessful)
        {
            LongRunningTask poll = new LongRunningTask(new AsyncCommand<Boolean>()
            {
                @Override
                public void execute(final AsyncCallback<Boolean> callback)
                {
                    final List<Server> finishedServers = new ArrayList<Server>();

                    for (Map.Entry<HostInfo, List<ServerInstance>> entry : serversPerHost
                            .entrySet())
                    {
                        HostInfo hostInfo = entry.getKey();
                        List<ServerInstance> serverInstances = entry.getValue();
                        for (ServerInstance serverInstance : serverInstances)
                        {
                            hostInfoStore.getServerConfiguration(hostInfo.getName(), serverInstance.getServer(),
                                    new SimpleCallback<Server>()
                                    {
                                        @Override
                                        public void onSuccess(final Server server)
                                        {
                                            finishedServers.add(server);
                                            boolean keepPolling = lifecycleOp == START || lifecycleOp == RESTART ? !server
                                                    .isStarted() : server.isStarted();
                                            if (!keepPolling && finishedServers.size() == servers)
                                            {
                                                ServerGroupLifecycleCallback.this.callback.onSuccess(finishedServers);
                                                Console.MODULES.getEventBus().fireEvent(
                                                        new StaleModelEvent(StaleModelEvent.SERVER_GROUPS)
                                                );
                                                Console.MODULES.getEventBus().fireEvent(
                                                        new StaleModelEvent(StaleModelEvent.SERVER_INSTANCES)
                                                );
                                            }
                                            callback.onSuccess(keepPolling);
                                        }
                                    });
                        }
                    }
                }
            }, lifecycleOp.limit());
            poll.schedule(500);
        }
    }
{'fraction_non_alphanumeric': 0.07400221729490022, 'fraction_numerical': 0.005728011825572801, 'mean_word_length': 1.6854378566112627, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 68, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3639027', 'n_tokens_mistral': 2444, 'n_tokens_neox': 2327, 'n_words': 629}