Package: RegionDigraphDumpContributor

RegionDigraphDumpContributor

nameinstructionbranchcomplexitylinemethod
RegionDigraphDumpContributor(BundleContext)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
contribute(Dump)
M: 41 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
getName()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011 VMware Inc.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * VMware Inc. - initial contribution
10: *******************************************************************************/
11:
12: package org.eclipse.virgo.nano.serviceability.dump.internal;
13:
14: import java.io.File;
15: import java.io.FileOutputStream;
16: import java.io.OutputStream;
17:
18: import org.eclipse.equinox.region.RegionDigraph;
19: import org.eclipse.virgo.nano.serviceability.NonNull;
20: import org.eclipse.virgo.medic.dump.Dump;
21: import org.eclipse.virgo.medic.dump.DumpContributionFailedException;
22: import org.eclipse.virgo.medic.dump.DumpContributor;
23: import org.osgi.framework.BundleContext;
24: import org.osgi.framework.ServiceReference;
25:
26: /**
27: * {@link RegionDigraphDumpContributor} dumps the {@link RegionDigraph} to a file.
28: * <p />
29: *
30: * <strong>Concurrent Semantics</strong><br />
31: * Thread safe.
32: */
33: public final class RegionDigraphDumpContributor implements DumpContributor {
34:
35: private final BundleContext bundleContext;
36:
37: public RegionDigraphDumpContributor(@NonNull BundleContext bundleContext) {
38: this.bundleContext = bundleContext;
39: }
40:
41: /**
42: * {@inheritDoc}
43: */
44: @Override
45: public void contribute(Dump dump) throws DumpContributionFailedException {
46: File outputFile = dump.createFile("region.digraph");
47: ServiceReference<RegionDigraph> serviceReference = this.bundleContext.getServiceReference(RegionDigraph.class);
48: RegionDigraph regionDigraph = this.bundleContext.getService(serviceReference);
49: try {
50: OutputStream output = new FileOutputStream(outputFile);
51: try {
52: regionDigraph.getRegionDigraphPersistence().save(regionDigraph, output);
53: } finally {
54: output.close();
55: }
56: } catch (Exception e) {
57: throw new DumpContributionFailedException("Failed to dump region digraph", e);
58: } finally {
59: this.bundleContext.ungetService(serviceReference);
60: }
61:
62: }
63:
64: /**
65: * {@inheritDoc}
66: */
67: @Override
68: public String getName() {
69: return "region digraph";
70: }
71:
72: }