001 /* 002 * Copyright (C) 2008-2010 by Holger Arndt 003 * 004 * This file is part of the Universal Java Matrix Package (UJMP). 005 * See the NOTICE file distributed with this work for additional 006 * information regarding copyright ownership and licensing. 007 * 008 * UJMP is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation; either version 2 011 * of the License, or (at your option) any later version. 012 * 013 * UJMP is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU Lesser General Public License for more details. 017 * 018 * You should have received a copy of the GNU Lesser General Public 019 * License along with UJMP; if not, write to the 020 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 021 * Boston, MA 02110-1301 USA 022 */ 023 024 package org.ujmp.core.util.matrices; 025 026 import java.util.ArrayList; 027 import java.util.Arrays; 028 import java.util.Collection; 029 import java.util.Collections; 030 import java.util.HashSet; 031 import java.util.Map; 032 import java.util.Set; 033 034 import org.ujmp.core.mapmatrix.AbstractMapMatrix; 035 import org.ujmp.core.mapmatrix.MapMatrix; 036 037 public class MatrixRunningThreads extends AbstractMapMatrix<Object, Object> { 038 private static final long serialVersionUID = -6988423129848472319L; 039 040 public MatrixRunningThreads() { 041 setLabel("Running Threads"); 042 } 043 044 public Map<Object, Object> getMap() { 045 return ThreadMap.getInstance(); 046 } 047 048 public MapMatrix<Object, Object> copy() { 049 return new MatrixRunningThreads(); 050 } 051 052 } 053 054 class ThreadMap implements Map<Object, Object> { 055 056 private static ThreadMap threadMap = null; 057 058 public static ThreadMap getInstance() { 059 if (threadMap == null) { 060 threadMap = new ThreadMap(); 061 } 062 return threadMap; 063 } 064 065 public void clear() { 066 } 067 068 public boolean containsKey(Object key) { 069 return Thread.getAllStackTraces().containsKey(key); 070 } 071 072 public boolean containsValue(Object value) { 073 return Thread.getAllStackTraces().containsValue(value); 074 } 075 076 public Set<java.util.Map.Entry<Object, Object>> entrySet() { 077 return Collections.emptySet(); 078 } 079 080 public Object get(Object key) { 081 return Arrays.asList(Thread.getAllStackTraces().get(key)); 082 } 083 084 public boolean isEmpty() { 085 return Thread.getAllStackTraces().isEmpty(); 086 } 087 088 public Set<Object> keySet() { 089 return new HashSet<Object>(Thread.getAllStackTraces().keySet()); 090 } 091 092 public Object put(Object key, Object value) { 093 return null; 094 } 095 096 public void putAll(Map<? extends Object, ? extends Object> m) { 097 } 098 099 public Object remove(Object key) { 100 return null; 101 } 102 103 public int size() { 104 return Thread.getAllStackTraces().size(); 105 } 106 107 public Collection<Object> values() { 108 return new ArrayList<Object>(Thread.getAllStackTraces().values()); 109 } 110 111 }