/* * Copyright (C) 2021 eichehome * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package server; import java.io.PipedWriter; import utils.FifoPipe; import utils.ArrayHelper; import utils.Client; /** * * @author eichehome */ public class ClientMessageStore { private ArrayHelper arrayHelper = new ArrayHelper<>(); /** * Verzeichniss der Threads, die die Clients überwachen */ private Client[] clientThreads = null; public synchronized void addClient(Thread thread, FifoPipe pipe) { Client client = new Client(thread, pipe); arrayHelper.push(client, clientThreads); } public synchronized Client removeClient(Thread thread) throws IllegalArgumentException { FifoPipe pipe = null; for (int i = 0; i < clientThreads.length; i++) { if (clientThreads[i].getThread().equals(thread)) { pipe = clientThreads[i].getPipe(); } } if (pipe != null) { Client client = new Client(thread, pipe); return arrayHelper.pop(client, clientThreads); } else { throw new IllegalArgumentException("Element not found"); } } public void notifyAllClients() { for (Client client : clientThreads) { client.getThread().interrupt(); } } }