xref: /onnv-gate/usr/src/lib/libdtrace_jni/java/docs/examples/TestAPI.java (revision 1449:5ac202d7f3a7)
1*1449Stomee /*
2*1449Stomee  * CDDL HEADER START
3*1449Stomee  *
4*1449Stomee  * The contents of this file are subject to the terms of the
5*1449Stomee  * Common Development and Distribution License (the "License").
6*1449Stomee  * You may not use this file except in compliance with the License.
7*1449Stomee  *
8*1449Stomee  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*1449Stomee  * or http://www.opensolaris.org/os/licensing.
10*1449Stomee  * See the License for the specific language governing permissions
11*1449Stomee  * and limitations under the License.
12*1449Stomee  *
13*1449Stomee  * When distributing Covered Code, include this CDDL HEADER in each
14*1449Stomee  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*1449Stomee  * If applicable, add the following below this CDDL HEADER, with the
16*1449Stomee  * fields enclosed by brackets "[]" replaced with your own identifying
17*1449Stomee  * information: Portions Copyright [yyyy] [name of copyright owner]
18*1449Stomee  *
19*1449Stomee  * CDDL HEADER END
20*1449Stomee  */
21*1449Stomee 
22*1449Stomee /*
23*1449Stomee  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*1449Stomee  * Use is subject to license terms.
25*1449Stomee  *
26*1449Stomee  * ident	"%Z%%M%	%I%	%E% SMI"
27*1449Stomee  */
28*1449Stomee 
29*1449Stomee import org.opensolaris.os.dtrace.*;
30*1449Stomee import java.io.File;
31*1449Stomee 
32*1449Stomee public class TestAPI {
33*1449Stomee     public static void
main(String[] args)34*1449Stomee     main(String[] args)
35*1449Stomee     {
36*1449Stomee 	if (args.length < 1) {
37*1449Stomee 	    System.err.println("Usage: java TestAPI <script> [ macroargs... ]");
38*1449Stomee 	    System.exit(2);
39*1449Stomee 	}
40*1449Stomee 
41*1449Stomee 	File file = new File(args[0]);
42*1449Stomee 	String[] macroArgs = new String[args.length - 1];
43*1449Stomee 	System.arraycopy(args, 1, macroArgs, 0, (args.length - 1));
44*1449Stomee 
45*1449Stomee 	Consumer consumer = new LocalConsumer();
46*1449Stomee 	consumer.addConsumerListener(new ConsumerAdapter() {
47*1449Stomee 	    public void dataReceived(DataEvent e) {
48*1449Stomee 		System.out.println(e.getProbeData());
49*1449Stomee 	    }
50*1449Stomee 	});
51*1449Stomee 
52*1449Stomee 	try {
53*1449Stomee 	    consumer.open();
54*1449Stomee 	    consumer.compile(file, macroArgs);
55*1449Stomee 	    consumer.enable();
56*1449Stomee 	    consumer.go();
57*1449Stomee 	} catch (Exception e) {
58*1449Stomee 	    e.printStackTrace();
59*1449Stomee 	    System.exit(1);
60*1449Stomee 	}
61*1449Stomee     }
62*1449Stomee }
63