1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * 26 * ident "%Z%%M% %I% %E% SMI" 27 */ 28 package org.opensolaris.os.dtrace; 29 30 import java.util.*; 31 32 /** 33 * Implementation detail used by {@link Consumer#getAggregate()}. 34 * Package level access. 35 * 36 * @author Tom Erickson 37 */ 38 class AggregateSpec { 39 private Set <String> includedAggregationNames; 40 private Set <String> clearedAggregationNames; 41 42 AggregateSpec() 43 { 44 includedAggregationNames = new HashSet <String> (); 45 clearedAggregationNames = new HashSet <String> (); 46 } 47 48 public boolean 49 isIncludeByDefault() 50 { 51 return (includedAggregationNames == null); 52 } 53 54 public boolean 55 isClearByDefault() 56 { 57 return (clearedAggregationNames == null); 58 } 59 60 public void 61 setIncludeByDefault(boolean include) 62 { 63 if (include) { 64 includedAggregationNames = null; 65 } else if (includedAggregationNames == null) { 66 includedAggregationNames = new HashSet <String> (); 67 } 68 } 69 70 public void 71 setClearByDefault(boolean clear) 72 { 73 if (clear) { 74 clearedAggregationNames = null; 75 } else if (clearedAggregationNames == null) { 76 clearedAggregationNames = new HashSet <String> (); 77 } 78 } 79 80 /** 81 * Specifies which aggregations to include in an aggregate snapshot. 82 * If none are specified, all aggregations are included. A snapshot 83 * is read-consistent across all included aggregations. 84 * 85 * @see Consumer#getAggregate(AggregateSpec spec) 86 */ 87 public void 88 addIncludedAggregationName(String name) 89 { 90 if (includedAggregationNames == null) { 91 includedAggregationNames = new HashSet <String> (); 92 } 93 includedAggregationNames.add(name); 94 } 95 96 /** 97 * Specifies which aggregations to clear after snapping the 98 * aggregate. If none are specified, no aggregations are cleared. 99 * <p> 100 * Aggregations are cleared immediately after they are snapped 101 * before any more data can be accumulated in order to prevent loss 102 * of data between snapshots. 103 * 104 * @see Consumer#getAggregate(AggregateSpec spec) 105 */ 106 public void 107 addClearedAggregationName(String name) 108 { 109 if (clearedAggregationNames == null) { 110 clearedAggregationNames = new HashSet <String> (); 111 } 112 clearedAggregationNames.add(name); 113 } 114 115 public Set <String> 116 getIncludedAggregationNames() 117 { 118 if (includedAggregationNames == null) { 119 return Collections. <String> emptySet(); 120 } 121 return Collections.unmodifiableSet(includedAggregationNames); 122 } 123 124 public Set <String> 125 getClearedAggregationNames() 126 { 127 if (clearedAggregationNames == null) { 128 return Collections. <String> emptySet(); 129 } 130 return Collections.unmodifiableSet(clearedAggregationNames); 131 } 132 133 public boolean 134 isIncluded(String aggregationName) 135 { 136 return ((includedAggregationNames == null) || 137 includedAggregationNames.contains(aggregationName)); 138 } 139 140 public boolean 141 isCleared(String aggregationName) 142 { 143 return ((clearedAggregationNames == null) || 144 clearedAggregationNames.contains(aggregationName)); 145 } 146 147 public String 148 toString() 149 { 150 StringBuilder buf = new StringBuilder(); 151 buf.append(AggregateSpec.class.getName()); 152 buf.append("[includedAggregationNames = "); 153 buf.append(Arrays.toString(getIncludedAggregationNames().toArray())); 154 buf.append(", clearedAggregationNames = "); 155 buf.append(Arrays.toString(getClearedAggregationNames().toArray())); 156 buf.append(", includeByDefault = "); 157 buf.append(isIncludeByDefault()); 158 buf.append(", clearByDefault = "); 159 buf.append(isClearByDefault()); 160 buf.append(']'); 161 return buf.toString(); 162 } 163 } 164