Omaha #3085 - re-deleted stuff that was re-added in the merge from omaha_14.3.1 to omaha_14.4.1
Change-Id: Id13953881429545bccb590a550c23a73f77d585e Former-commit-id: 75d4816f97b0b6fa2bf93847038c4f15b3479e39
This commit is contained in:
parent
b7272b3248
commit
70ee74a311
22 changed files with 0 additions and 3101 deletions
|
@ -1,135 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.dataquery.requests;
|
||||
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
|
||||
import com.raytheon.uf.common.serialization.comm.IServerRequest;
|
||||
|
||||
/**
|
||||
* The request class to coordinate with the shared locks in the
|
||||
* awips.custer_task table.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 1, 2014 2862 rferrel Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rferrel
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
@DynamicSerialize
|
||||
public class SharedLockRequest implements IServerRequest {
|
||||
/** The types of requests. */
|
||||
public static enum RequestType {
|
||||
READER_LOCK, READER_UNLOCK, READER_UPDATE_TIME, WRITER_LOCK, WRITER_UNLOCK, WRITER_UPDATE_TIME
|
||||
}
|
||||
|
||||
/** The name column entry. */
|
||||
@DynamicSerializeElement
|
||||
private String name;
|
||||
|
||||
/** The details column entry. */
|
||||
@DynamicSerializeElement
|
||||
private String details;
|
||||
|
||||
/* The desired request. */
|
||||
@DynamicSerializeElement
|
||||
private RequestType requestType;
|
||||
|
||||
/**
|
||||
* Default constructor should only be used for serialization.
|
||||
*/
|
||||
public SharedLockRequest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Desired constructor.
|
||||
*
|
||||
* @param details
|
||||
* @param requestType
|
||||
*/
|
||||
public SharedLockRequest(String name, String details,
|
||||
RequestType requestType) {
|
||||
setName(name);
|
||||
setDetails(details);
|
||||
setRequestType(requestType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter.
|
||||
*
|
||||
* @return requestType
|
||||
*/
|
||||
public RequestType getRequestType() {
|
||||
return requestType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter should only be used for serialization.
|
||||
*
|
||||
* @param requestType
|
||||
*/
|
||||
public void setRequestType(RequestType requestType) {
|
||||
this.requestType = requestType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter.
|
||||
*
|
||||
* @return name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter.
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter.
|
||||
*
|
||||
* @return details
|
||||
*/
|
||||
public String getDetails() {
|
||||
return details;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter should only be used for serialization.
|
||||
*
|
||||
* @param details
|
||||
*/
|
||||
public void setDetails(String details) {
|
||||
this.details = details;
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.dataquery.responses;
|
||||
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
|
||||
|
||||
/**
|
||||
* Response from the shared lock request handler.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 8, 2014 2862 rferrel Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rferrel
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
@DynamicSerialize
|
||||
public class SharedLockResponse {
|
||||
/** true when request was successful. */
|
||||
@DynamicSerializeElement
|
||||
private boolean sucessful;
|
||||
|
||||
/** Any error message from the handler. */
|
||||
@DynamicSerializeElement
|
||||
private String errorMessage;
|
||||
|
||||
public boolean isSucessful() {
|
||||
return sucessful;
|
||||
}
|
||||
|
||||
public void setSucessful(boolean sucessful) {
|
||||
this.sucessful = sucessful;
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
}
|
|
@ -1,344 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.geospatial;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.geotools.geometry.jts.CoordinateSequenceTransformer;
|
||||
import org.geotools.geometry.jts.DefaultCoordinateSequenceTransformer;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
import org.opengis.referencing.operation.MathTransform;
|
||||
import org.opengis.referencing.operation.TransformException;
|
||||
|
||||
import com.vividsolutions.jts.geom.CoordinateSequence;
|
||||
import com.vividsolutions.jts.geom.CoordinateSequenceFactory;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.geom.GeometryCollection;
|
||||
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||
import com.vividsolutions.jts.geom.LineString;
|
||||
import com.vividsolutions.jts.geom.LinearRing;
|
||||
import com.vividsolutions.jts.geom.MultiLineString;
|
||||
import com.vividsolutions.jts.geom.MultiPoint;
|
||||
import com.vividsolutions.jts.geom.MultiPolygon;
|
||||
import com.vividsolutions.jts.geom.Point;
|
||||
import com.vividsolutions.jts.geom.Polygon;
|
||||
|
||||
/**
|
||||
* Replacement for GeoTools GeometryCoordinateSequenceTransformer that can
|
||||
* handle conversion of polygons containing NaNs.
|
||||
*
|
||||
* Had to copy the entire class and modify it since it was not written to be
|
||||
* subclassed.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 16, 2014 #2997 randerso Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author randerso
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class GeometryTransformer {
|
||||
|
||||
private MathTransform transform = null;
|
||||
|
||||
private CoordinateReferenceSystem crs;
|
||||
|
||||
private CoordinateSequenceTransformer inputCSTransformer = null;
|
||||
|
||||
private CoordinateSequenceTransformer csTransformer = null;
|
||||
|
||||
private GeometryFactory currGeometryFactory = null;
|
||||
|
||||
/**
|
||||
* Creates a transformer which uses the {@link CoordinateSequenceFactory} of
|
||||
* the source geometries.
|
||||
*/
|
||||
public GeometryTransformer() {
|
||||
// the csTransformer is initialized from the first geometry
|
||||
// and the supplied transform
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a transformer which uses a client-specified
|
||||
* {@link CoordinateSequenceTransformer}.
|
||||
* <p>
|
||||
* <b>WARNING:</b> The CoordinateSequenceTransformer must use the same
|
||||
* {@link CoordinateSequenceFactory} as the output GeometryFactory, so that
|
||||
* geometries are constructed consistently.
|
||||
*
|
||||
* @param transformer
|
||||
*/
|
||||
public GeometryTransformer(CoordinateSequenceTransformer transformer) {
|
||||
inputCSTransformer = transformer;
|
||||
csTransformer = transformer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the math transform to be used for transformation
|
||||
*
|
||||
* @param transform
|
||||
*/
|
||||
public void setMathTransform(MathTransform transform) {
|
||||
this.transform = transform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target coordinate reference system.
|
||||
* <p>
|
||||
* This value is used to set the coordinate reference system of geometries
|
||||
* after they have been transformed.
|
||||
* </p>
|
||||
*
|
||||
* @param crs
|
||||
* The target coordinate reference system.
|
||||
*/
|
||||
public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs) {
|
||||
this.crs = crs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the internal CoordinateSequenceTransformer if not specified
|
||||
* explicitly.
|
||||
*
|
||||
* @param gf
|
||||
* the factory to use
|
||||
*/
|
||||
private void init(GeometryFactory gf) {
|
||||
// don't init if csTransformer already exists
|
||||
if (inputCSTransformer != null) {
|
||||
return;
|
||||
}
|
||||
// don't reinit if gf is the same (the usual case)
|
||||
if (currGeometryFactory == gf) {
|
||||
return;
|
||||
}
|
||||
|
||||
currGeometryFactory = gf;
|
||||
CoordinateSequenceFactory csf = gf.getCoordinateSequenceFactory();
|
||||
csTransformer = new DefaultCoordinateSequenceTransformer(csf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the transform to the provided geometry, creating a new
|
||||
* transformed geometry.
|
||||
*
|
||||
* @param g
|
||||
* the geometry to transform
|
||||
* @return a new transformed geometry
|
||||
* @throws TransformException
|
||||
*/
|
||||
public Geometry transform(Geometry g) throws TransformException {
|
||||
GeometryFactory factory = g.getFactory();
|
||||
Geometry transformed = null;
|
||||
|
||||
// lazily init csTransformer using geometry's CSFactory
|
||||
init(factory);
|
||||
|
||||
if (g instanceof Point) {
|
||||
transformed = transformPoint((Point) g, factory);
|
||||
} else if (g instanceof MultiPoint) {
|
||||
MultiPoint mp = (MultiPoint) g;
|
||||
Point[] points = new Point[mp.getNumGeometries()];
|
||||
|
||||
for (int i = 0; i < points.length; i++) {
|
||||
points[i] = transformPoint((Point) mp.getGeometryN(i), factory);
|
||||
}
|
||||
|
||||
transformed = factory.createMultiPoint(points);
|
||||
} else if (g instanceof LineString) {
|
||||
transformed = transformLineString((LineString) g, factory);
|
||||
} else if (g instanceof MultiLineString) {
|
||||
MultiLineString mls = (MultiLineString) g;
|
||||
LineString[] lines = new LineString[mls.getNumGeometries()];
|
||||
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
lines[i] = transformLineString(
|
||||
(LineString) mls.getGeometryN(i), factory);
|
||||
}
|
||||
|
||||
transformed = factory.createMultiLineString(lines);
|
||||
} else if (g instanceof Polygon) {
|
||||
transformed = transformPolygon((Polygon) g, factory);
|
||||
} else if (g instanceof MultiPolygon) {
|
||||
// changed from original GeoTools implementation
|
||||
// to handle transformPolygon possibly returning LineStrings instead for polygons
|
||||
MultiPolygon mp = (MultiPolygon) g;
|
||||
int n = mp.getNumGeometries();
|
||||
List<Geometry> polygons = new ArrayList<Geometry>(n);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
polygons.add(transformPolygon((Polygon) mp.getGeometryN(i),
|
||||
factory));
|
||||
}
|
||||
|
||||
transformed = factory.buildGeometry(polygons);
|
||||
} else if (g instanceof GeometryCollection) {
|
||||
GeometryCollection gc = (GeometryCollection) g;
|
||||
Geometry[] geoms = new Geometry[gc.getNumGeometries()];
|
||||
|
||||
for (int i = 0; i < geoms.length; i++) {
|
||||
geoms[i] = transform(gc.getGeometryN(i));
|
||||
}
|
||||
|
||||
transformed = factory.createGeometryCollection(geoms);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported geometry type "
|
||||
+ g.getClass());
|
||||
}
|
||||
|
||||
// copy over user data
|
||||
// do a special check for coordinate reference system
|
||||
transformed.setUserData(g.getUserData());
|
||||
|
||||
if ((g.getUserData() == null)
|
||||
|| (g.getUserData() instanceof CoordinateReferenceSystem)) {
|
||||
// set the new one to be the target crs
|
||||
if (crs != null) {
|
||||
transformed.setUserData(crs);
|
||||
}
|
||||
}
|
||||
|
||||
return transformed;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ls
|
||||
* @param gf
|
||||
* @return transformed lineString
|
||||
* @throws TransformException
|
||||
*/
|
||||
public LineString transformLineString(LineString ls, GeometryFactory gf)
|
||||
throws TransformException {
|
||||
|
||||
// if required, init csTransformer using geometry's CSFactory
|
||||
init(gf);
|
||||
|
||||
CoordinateSequence cs = projectCoordinateSequence(ls
|
||||
.getCoordinateSequence());
|
||||
LineString transformed = null;
|
||||
|
||||
// changed from original GeoTools implementation
|
||||
// to check if CoordinateSequence is closed and return LineString if not
|
||||
if (isClosed(cs)) {
|
||||
transformed = gf.createLinearRing(cs);
|
||||
} else {
|
||||
transformed = gf.createLineString(cs);
|
||||
}
|
||||
|
||||
transformed.setUserData(ls.getUserData());
|
||||
return transformed;
|
||||
}
|
||||
|
||||
// changed from original GeoTools implementation
|
||||
// added function to check if CoordinateSequence
|
||||
// is closed and contains enough points to be a
|
||||
// LinearRing
|
||||
private boolean isClosed(CoordinateSequence cs) {
|
||||
if (cs.size() < 4) {
|
||||
return false;
|
||||
}
|
||||
return cs.getCoordinate(0).equals2D(cs.getCoordinate(cs.size() - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param point
|
||||
* @param gf
|
||||
* @return transformed point
|
||||
*
|
||||
* @throws TransformException
|
||||
*/
|
||||
public Point transformPoint(Point point, GeometryFactory gf)
|
||||
throws TransformException {
|
||||
|
||||
// if required, init csTransformer using geometry's CSFactory
|
||||
init(gf);
|
||||
|
||||
CoordinateSequence cs = projectCoordinateSequence(point
|
||||
.getCoordinateSequence());
|
||||
Point transformed = gf.createPoint(cs);
|
||||
transformed.setUserData(point.getUserData());
|
||||
return transformed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cs
|
||||
* a CoordinateSequence
|
||||
* @return
|
||||
*
|
||||
* @throws TransformException
|
||||
*/
|
||||
private CoordinateSequence projectCoordinateSequence(CoordinateSequence cs)
|
||||
throws TransformException {
|
||||
return csTransformer.transform(cs, transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param polygon
|
||||
* @param gf
|
||||
* @return transformed Polygon or MultiLineString if Polygon no longer
|
||||
* closes
|
||||
* @throws TransformException
|
||||
*/
|
||||
public Geometry transformPolygon(Polygon polygon, GeometryFactory gf)
|
||||
throws TransformException {
|
||||
// changed from original GeoTools implementation
|
||||
// to return LineStrings if polygon no longer closed due to NaNs
|
||||
// returned by projection transformation (point outside valid range for projection)
|
||||
LineString[] lineStrings = new LineString[polygon.getNumInteriorRing() + 1];
|
||||
|
||||
lineStrings[0] = transformLineString(polygon.getExteriorRing(), gf);
|
||||
|
||||
for (int i = 1; i < lineStrings.length; i++) {
|
||||
lineStrings[i] = transformLineString(
|
||||
polygon.getInteriorRingN(i - 1), gf);
|
||||
}
|
||||
|
||||
boolean closed = true;
|
||||
for (LineString ls : lineStrings) {
|
||||
if (!ls.isClosed()) {
|
||||
closed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Geometry transformed;
|
||||
if (closed) {
|
||||
LinearRing[] interiors = new LinearRing[lineStrings.length - 1];
|
||||
for (int i = 0; i < interiors.length; i++) {
|
||||
interiors[i] = (LinearRing) lineStrings[i + 1];
|
||||
}
|
||||
transformed = gf.createPolygon((LinearRing) lineStrings[0],
|
||||
interiors);
|
||||
} else {
|
||||
transformed = gf.createMultiLineString(lineStrings);
|
||||
}
|
||||
transformed.setUserData(polygon.getUserData());
|
||||
return transformed;
|
||||
}
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.util.collections;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* Map implementation that limits the map to a specified number of entries.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 14, 2014 2726 rjpeter Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
* @param <K>
|
||||
* @param <V>
|
||||
*/
|
||||
public class BoundedMap<K, V> extends LinkedHashMap<K, V> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final int DEFAULT_INITIAL_SIZE = 16;
|
||||
|
||||
private static final float DEFAULT_LOAD_FACTOR = 0.75f;
|
||||
|
||||
private final int maxSize;
|
||||
|
||||
/**
|
||||
* BoundedMap with specified max size. Defaults to accessOrder elimination.
|
||||
*
|
||||
* @param maxSize
|
||||
*/
|
||||
public BoundedMap(int maxSize) {
|
||||
this(maxSize, DEFAULT_INITIAL_SIZE, DEFAULT_LOAD_FACTOR, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* BoundedMap with specified initial and max size. Defaults to accessOrder
|
||||
* elimination.
|
||||
*
|
||||
* @param maxSize
|
||||
* @param initialSize
|
||||
*/
|
||||
public BoundedMap(int maxSize, int initialSize) {
|
||||
this(maxSize, initialSize, DEFAULT_LOAD_FACTOR, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* BoundedMap with specified initial size, max size, and loadFactor.
|
||||
* Defaults to accessOrder elimination.
|
||||
*
|
||||
* @param maxSize
|
||||
* @param initialSize
|
||||
* @param loadFactor
|
||||
*/
|
||||
public BoundedMap(int maxSize, int initialSize, float loadFactor) {
|
||||
this(maxSize, initialSize, loadFactor, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* BoundedMap with specified initial size, max size, loadFactor, and
|
||||
* accessOrder elimination. If accessOrder is true, map is order by
|
||||
* accessOrder, false is insertion order.
|
||||
*
|
||||
* @param maxSize
|
||||
* @param initialSize
|
||||
* @param loadFactor
|
||||
* @param accessOrder
|
||||
*/
|
||||
public BoundedMap(int maxSize, int initialSize, float loadFactor,
|
||||
boolean accessOrder) {
|
||||
super(initialSize, loadFactor, accessOrder);
|
||||
this.maxSize = maxSize;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.util.LinkedHashMap#removeEldestEntry(java.util.Map.Entry)
|
||||
*/
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Entry<K, V> eldest) {
|
||||
return size() > maxSize;
|
||||
}
|
||||
}
|
|
@ -1,175 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.util.stream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Stream that counts the number of bytes that have been read.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 15, 2014 2928 rjpeter Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
public class CountingInputStream extends InputStream {
|
||||
/**
|
||||
* Stream to get data from.
|
||||
*/
|
||||
protected final InputStream wrappedStream;
|
||||
|
||||
/**
|
||||
* Number of bytes that have been read.
|
||||
*/
|
||||
protected long bytesRead = 0;
|
||||
|
||||
/**
|
||||
* Wraps the passed {@code InputStream} counting the bytes that are read
|
||||
* from it.
|
||||
*
|
||||
* @param inputStream
|
||||
*/
|
||||
public CountingInputStream(InputStream inputStream) {
|
||||
this.wrappedStream = inputStream;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.io.InputStream#read(byte[])
|
||||
*/
|
||||
@Override
|
||||
public int read(byte[] b) throws IOException {
|
||||
return read(b, 0, b.length);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.io.InputStream#read(byte[], int, int)
|
||||
*/
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
int rval = wrappedStream.read(b, off, len);
|
||||
increaseBytesRead(rval);
|
||||
return rval;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.io.InputStream#skip(long)
|
||||
*/
|
||||
@Override
|
||||
public long skip(long n) throws IOException {
|
||||
return wrappedStream.skip(n);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.io.InputStream#available()
|
||||
*/
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
return wrappedStream.available();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the underlying stream. Nothing in this stream needs to be closed
|
||||
* as long as the wrappedStream is closed.
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
wrappedStream.close();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.io.InputStream#mark(int)
|
||||
*/
|
||||
@Override
|
||||
public synchronized void mark(int readlimit) {
|
||||
wrappedStream.mark(readlimit);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.io.InputStream#reset()
|
||||
*/
|
||||
@Override
|
||||
public synchronized void reset() throws IOException {
|
||||
wrappedStream.reset();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.io.InputStream#markSupported()
|
||||
*/
|
||||
@Override
|
||||
public boolean markSupported() {
|
||||
return wrappedStream.markSupported();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.io.InputStream#read()
|
||||
*/
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
int rval = wrappedStream.read();
|
||||
increaseBytesRead(1);
|
||||
return rval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that updates the internal count of the number of bytes read. Also
|
||||
* useful extension point for special handling based on amount of bytes
|
||||
* read.
|
||||
*
|
||||
* @param bytesRead
|
||||
* @throws IOException
|
||||
*/
|
||||
public void increaseBytesRead(int bytesRead) throws IOException {
|
||||
this.bytesRead += bytesRead;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bytes read so far.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getBytesRead() {
|
||||
return bytesRead;
|
||||
}
|
||||
}
|
|
@ -1,133 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.util.stream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Stream that counts the number of bytes that have been written.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 15, 2014 2928 rjpeter Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
public class CountingOutputStream extends OutputStream {
|
||||
/**
|
||||
* Stream to write data to.
|
||||
*/
|
||||
protected final OutputStream wrappedStream;
|
||||
|
||||
/**
|
||||
* Number of bytes that have been written.
|
||||
*/
|
||||
protected long bytesWritten = 0;
|
||||
|
||||
/**
|
||||
* Wraps the passed {@code OutputStream} counting the bytes that are written
|
||||
* to it.
|
||||
*
|
||||
* @param outputStream
|
||||
*/
|
||||
public CountingOutputStream(OutputStream outputStream) {
|
||||
this.wrappedStream = outputStream;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.io.OutputStream#write(byte[])
|
||||
*/
|
||||
@Override
|
||||
public void write(byte[] b) throws IOException {
|
||||
this.write(b, 0, b.length);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.io.OutputStream#write(byte[], int, int)
|
||||
*/
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
wrappedStream.write(b, off, len);
|
||||
increaseBytesWritten(len);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.io.OutputStream#flush()
|
||||
*/
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
wrappedStream.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the underlying stream. Nothing in this stream needs to be closed
|
||||
* as long as the wrappedStream is closed.
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
wrappedStream.close();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.io.OutputStream#write(int)
|
||||
*/
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
wrappedStream.write(b);
|
||||
increaseBytesWritten(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that updates the internal count of the number of bytes written.
|
||||
* Also useful extension point for special handling based on amount of bytes
|
||||
* written.
|
||||
*
|
||||
* @param bytesRead
|
||||
* @throws IOException
|
||||
*/
|
||||
public void increaseBytesWritten(int bytesWritten) throws IOException {
|
||||
this.bytesWritten += bytesWritten;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bytes written so far.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getBytesWritten() {
|
||||
return bytesWritten;
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.util.stream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.raytheon.uf.common.util.SizeUtil;
|
||||
|
||||
/**
|
||||
* Stream that limits the number of bytes that can be read. If limit is reached
|
||||
* an IOException is thrown. This does not preclude more bytes being read from
|
||||
* the stream.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 15, 2014 2928 rjpeter Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
public class LimitingInputStream extends CountingInputStream {
|
||||
/**
|
||||
* Maximum number of bytes that can be read from the wrapped stream before
|
||||
* errors are thrown on read.
|
||||
*/
|
||||
protected final long maxBytes;
|
||||
|
||||
/**
|
||||
* Wraps the given {@code InputStream} and will throw IOException once the
|
||||
* specified number of bytes have been read from the stream.
|
||||
*
|
||||
* @param inputStream
|
||||
* @param maxBytes
|
||||
*/
|
||||
public LimitingInputStream(InputStream inputStream, long maxBytes) {
|
||||
super(inputStream);
|
||||
this.maxBytes = maxBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tracks number of bytes read from wrapped stream. An IOException will be
|
||||
* thrown if number of bytes read exceeds {@code maxBytes}.
|
||||
*
|
||||
* @param bytesRead
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void increaseBytesRead(int bytesRead) throws IOException {
|
||||
super.increaseBytesRead(bytesRead);
|
||||
long curBytes = getBytesRead();
|
||||
if (curBytes > maxBytes) {
|
||||
throw new IOException("Maximum number of bytes ["
|
||||
+ SizeUtil.prettyByteSize(maxBytes)
|
||||
+ "] has been exceeded by stream");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.util.stream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import com.raytheon.uf.common.util.SizeUtil;
|
||||
|
||||
/**
|
||||
* Stream that limits the number of bytes that can be written. If limit is
|
||||
* reached an IOException is thrown. This does not preclude more bytes from
|
||||
* being written to the stream.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 15, 2014 2928 rjpeter Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
public class LimitingOutputStream extends CountingOutputStream {
|
||||
/**
|
||||
* Maximum number of bytes that can be written to the wrapped stream before
|
||||
* errors are thrown on write.
|
||||
*/
|
||||
protected final long maxBytes;
|
||||
|
||||
/**
|
||||
* Wraps the given {@code OutputStream} and will throw IOException once the
|
||||
* specified number of bytes have been written to the stream.
|
||||
*
|
||||
* @param inputStream
|
||||
* @param maxBytes
|
||||
*/
|
||||
public LimitingOutputStream(OutputStream outputStream, long maxBytes) {
|
||||
super(outputStream);
|
||||
this.maxBytes = maxBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tracks number of bytes written to wrapped stream. An IOException will be
|
||||
* thrown if number of bytes written exceeds {@code maxBytes}.
|
||||
*
|
||||
* @param bytesWritten
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void increaseBytesWritten(int bytesWritten) throws IOException {
|
||||
super.increaseBytesWritten(bytesWritten);
|
||||
long curBytes = getBytesWritten();
|
||||
if (curBytes > maxBytes) {
|
||||
throw new IOException("Maximum number of bytes ["
|
||||
+ SizeUtil.prettyByteSize(maxBytes)
|
||||
+ "] has been exceeded by stream");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
# byte limit for input and output streams to the thrift service.
|
||||
# After specified number of bytes, the stream is rejected to
|
||||
# prevent jvm OutOfMemory as the client is doing something wrong.
|
||||
thriftService.byteLimitInMB=100
|
|
@ -1,174 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.edex.core;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
|
||||
/**
|
||||
* Base class for Timer based threading. Allows previous thread based paradigms
|
||||
* to hook in to a camel context with minimal work.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 19, 2014 2826 rjpeter Initial creation.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
public abstract class EdexTimerBasedThread implements IContextStateProcessor {
|
||||
/**
|
||||
* Number of threads that have been started.
|
||||
*/
|
||||
protected final AtomicInteger threadCount = new AtomicInteger(0);
|
||||
|
||||
/**
|
||||
* Current active threads.
|
||||
*/
|
||||
protected final List<Thread> threads = new LinkedList<Thread>();
|
||||
|
||||
/**
|
||||
* Whether the container is running or not.
|
||||
*/
|
||||
protected volatile boolean running = true;
|
||||
|
||||
/**
|
||||
* Interval thread should sleep between calls.
|
||||
*/
|
||||
protected int threadSleepInterval = 30000;
|
||||
|
||||
/**
|
||||
* The name to use for the threads.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String getThreadGroupName();
|
||||
|
||||
/**
|
||||
* Method to do the work. Should return when done. Run method handles start
|
||||
* up/shutdown mechanism.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public abstract void process() throws Exception;
|
||||
|
||||
/**
|
||||
* Can be overridden to do any work to cleanup the thread on shutdown.
|
||||
*/
|
||||
public void dispose() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by camel to do the processing. Will run until the context is
|
||||
* shutdown.
|
||||
*/
|
||||
public void run() {
|
||||
synchronized (threads) {
|
||||
threads.add(Thread.currentThread());
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.currentThread().setName(
|
||||
getThreadGroupName() + "-" + threadCount.incrementAndGet());
|
||||
|
||||
while (running) {
|
||||
try {
|
||||
process();
|
||||
} catch (Exception e) {
|
||||
UFStatus.getHandler().error(
|
||||
"Error occurred during processing", e);
|
||||
}
|
||||
|
||||
if (running) {
|
||||
try {
|
||||
/*
|
||||
* use waiter to allow shutdown to wake thread for
|
||||
* immediate shutdown
|
||||
*/
|
||||
synchronized (threads) {
|
||||
threads.wait(threadSleepInterval);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
synchronized (threads) {
|
||||
threads.remove(Thread.currentThread());
|
||||
threads.notify();
|
||||
}
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preStart() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postStart() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preStop() {
|
||||
running = false;
|
||||
synchronized (threads) {
|
||||
threads.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postStop() {
|
||||
IUFStatusHandler statusHandler = UFStatus.getHandler();
|
||||
String msg = "Waiting for " + getThreadGroupName()
|
||||
+ " threads to finish";
|
||||
|
||||
synchronized (threads) {
|
||||
while (!threads.isEmpty()) {
|
||||
statusHandler.info(msg);
|
||||
try {
|
||||
threads.wait(10000);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getThreadSleepInterval() {
|
||||
return threadSleepInterval;
|
||||
}
|
||||
|
||||
public void setThreadSleepInterval(int threadSleepInterval) {
|
||||
this.threadSleepInterval = threadSleepInterval;
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.edex.core;
|
||||
|
||||
/**
|
||||
* Methods to be called as part of the context life cycle for starting and
|
||||
* stopping the context.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Feb 26, 2014 2726 rjpeter Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface IContextStateProcessor {
|
||||
|
||||
/**
|
||||
* Perform any work that needs to be done before the context is started,
|
||||
* such as initialization.
|
||||
*/
|
||||
public void preStart();
|
||||
|
||||
/**
|
||||
* Perform any work that needs to be done after the context is started, such
|
||||
* as sending notifications to clients.
|
||||
*/
|
||||
public void postStart();
|
||||
|
||||
/**
|
||||
* Perform any work that needs to be done before context is stopped, such as
|
||||
* notifying async threads to stop.
|
||||
*/
|
||||
public void preStop();
|
||||
|
||||
/**
|
||||
* Perform any work that needs to be done after the context is stopped, such
|
||||
* as sending in memory data.
|
||||
*/
|
||||
public void postStop();
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.edex.core.exception;
|
||||
|
||||
import com.raytheon.uf.edex.core.EdexException;
|
||||
|
||||
/**
|
||||
* Exception thrown during shutdown to allow for easy restart of transacted
|
||||
* tasks.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 23, 2014 2726 rjpeter Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ShutdownException extends EdexException {
|
||||
|
||||
/**
|
||||
* Default serial verion UID
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ShutdownException() {
|
||||
super("Aborting process, EDEX shutting down");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Shutdown Exception instance from only a message
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public ShutdownException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Shutdown Exception instance from both a message and a cause
|
||||
*
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public ShutdownException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||
|
||||
<!-- Instantiate the handler class for RemoteScriptList Handler -->
|
||||
<bean id="SharedLockRequestHandler"
|
||||
class="com.raytheon.uf.edex.database.handlers.SharedLockRequestHandler"/>
|
||||
|
||||
<!-- Register the handler class with the RemoteScriptListRequest Register. -->
|
||||
<bean id="sharedLockRequest" factory-bean="handlerRegistry" factory-method="register">
|
||||
<constructor-arg value="com.raytheon.uf.common.dataquery.requests.SharedLockRequest"/>
|
||||
<constructor-arg ref="SharedLockRequestHandler"/>
|
||||
</bean>
|
||||
</beans>
|
||||
|
|
@ -1,239 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.edex.database.handlers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.raytheon.uf.common.dataquery.requests.SharedLockRequest;
|
||||
import com.raytheon.uf.common.dataquery.requests.SharedLockRequest.RequestType;
|
||||
import com.raytheon.uf.common.dataquery.responses.SharedLockResponse;
|
||||
import com.raytheon.uf.common.serialization.comm.IRequestHandler;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.edex.database.cluster.ClusterLockUtils;
|
||||
import com.raytheon.uf.edex.database.cluster.ClusterLockUtils.LockState;
|
||||
import com.raytheon.uf.edex.database.cluster.ClusterTask;
|
||||
import com.raytheon.uf.edex.database.cluster.handler.SharedLockHandler;
|
||||
import com.raytheon.uf.edex.database.cluster.handler.SharedLockHandler.LockType;
|
||||
|
||||
/**
|
||||
* This is the handler class for a shared lock request. It coordinates with the
|
||||
* shared lock handler to perform the desired request.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 2, 2014 2862 rferrel Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rferrel
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class SharedLockRequestHandler implements
|
||||
IRequestHandler<SharedLockRequest> {
|
||||
|
||||
private final IUFStatusHandler statusHander = UFStatus
|
||||
.getHandler(SharedLockRequestHandler.class);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.uf.common.serialization.comm.IRequestHandler#handleRequest
|
||||
* (com.raytheon.uf.common.serialization.comm.IServerRequest)
|
||||
*/
|
||||
@Override
|
||||
public SharedLockResponse handleRequest(SharedLockRequest request)
|
||||
throws Exception {
|
||||
|
||||
SharedLockResponse response = new SharedLockResponse();
|
||||
String name = request.getName();
|
||||
String details = request.getDetails();
|
||||
RequestType type = request.getRequestType();
|
||||
response.setSucessful(false);
|
||||
|
||||
try {
|
||||
switch (type) {
|
||||
case READER_LOCK:
|
||||
if (lock(name, details, LockType.READER)) {
|
||||
response.setSucessful(true);
|
||||
} else {
|
||||
response.setSucessful(false);
|
||||
response.setErrorMessage(String.format(
|
||||
"Unable to obtain %s lock.", LockType.READER));
|
||||
}
|
||||
break;
|
||||
case READER_UNLOCK:
|
||||
if (unlock(name, details, LockType.READER)) {
|
||||
response.setSucessful(true);
|
||||
} else {
|
||||
response.setSucessful(false);
|
||||
response.setErrorMessage(String.format(
|
||||
"Unable to unlock %s.", LockType.READER));
|
||||
}
|
||||
break;
|
||||
case READER_UPDATE_TIME:
|
||||
if (updateTime(name, details, LockType.READER)) {
|
||||
response.setSucessful(true);
|
||||
} else {
|
||||
response.setSucessful(false);
|
||||
response.setErrorMessage(String.format(
|
||||
"Unable to update %s last exection time.",
|
||||
LockType.READER));
|
||||
}
|
||||
break;
|
||||
case WRITER_LOCK:
|
||||
if (lock(name, details, LockType.WRITER)) {
|
||||
response.setSucessful(true);
|
||||
} else {
|
||||
response.setSucessful(false);
|
||||
response.setErrorMessage(String.format(
|
||||
"Unable to obtain %s lock.", LockType.WRITER));
|
||||
}
|
||||
break;
|
||||
case WRITER_UNLOCK:
|
||||
if (unlock(name, details, LockType.WRITER)) {
|
||||
response.setSucessful(true);
|
||||
} else {
|
||||
response.setSucessful(false);
|
||||
response.setErrorMessage(String.format(
|
||||
"Unable to unlock %s.", LockType.WRITER));
|
||||
}
|
||||
break;
|
||||
case WRITER_UPDATE_TIME:
|
||||
if (updateTime(name, details, LockType.WRITER)) {
|
||||
response.setSucessful(false);
|
||||
response.setErrorMessage(String.format(
|
||||
"Unable to update %s last execution time.",
|
||||
LockType.WRITER));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
String message = "Unimplemented request type: " + type;
|
||||
statusHander.error(message);
|
||||
response.setErrorMessage(message);
|
||||
response.setSucessful(false);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
response.setSucessful(false);
|
||||
String message = String.format(
|
||||
"Request type %s for details %s failed %s", type, details,
|
||||
ex.getMessage());
|
||||
response.setErrorMessage(message);
|
||||
if (statusHander.isPriorityEnabled(Priority.PROBLEM)) {
|
||||
statusHander.handle(Priority.PROBLEM, message, ex);
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request details lock of the desired lock type.
|
||||
*
|
||||
* @param details
|
||||
* @param lockType
|
||||
* @return true when obtaining lock is successful
|
||||
*/
|
||||
private boolean lock(String name, String details, LockType lockType) {
|
||||
SharedLockHandler lockHandler = new SharedLockHandler(lockType);
|
||||
ClusterTask ct = ClusterLockUtils.lock(name, details, lockHandler,
|
||||
false);
|
||||
return LockState.SUCCESSFUL.equals(ct.getLockState());
|
||||
}
|
||||
|
||||
/**
|
||||
* Release lock for given details. The unlock request is only attempted when
|
||||
* the details' lock type matches and the count is a positive number.
|
||||
*
|
||||
* @param details
|
||||
* @param lockType
|
||||
* @return true when successful
|
||||
*/
|
||||
private boolean unlock(String name, String details, LockType lockType) {
|
||||
ClusterTask ct = findCluster(name, details, lockType);
|
||||
if (ct != null) {
|
||||
SharedLockHandler handler = (SharedLockHandler) ct.getLockHandler();
|
||||
if (handler.getLockCount() > 0) {
|
||||
return ClusterLockUtils.unlock(ct, false);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the details' cluster task with latest extrainfo and set up its
|
||||
* handler. The found cluster task is only returned if its lock type matches
|
||||
* the requested type and it is in the run state.
|
||||
*
|
||||
* @param details
|
||||
* - Whose cluster task to find
|
||||
* @param lockType
|
||||
* - Expected lock type for the cluster
|
||||
* @return ct when found, matches lockType, and is running else null.
|
||||
*/
|
||||
private ClusterTask findCluster(String name, String details,
|
||||
LockType lockType) {
|
||||
ClusterTask ct = null;
|
||||
List<ClusterTask> cts = ClusterLockUtils.getLocks(name);
|
||||
|
||||
if ((cts != null) && (cts.size() > 0)) {
|
||||
for (ClusterTask tmpCt : cts) {
|
||||
if (details.equals(tmpCt.getId().getDetails())) {
|
||||
if (tmpCt.isRunning()) {
|
||||
SharedLockHandler handler = new SharedLockHandler(
|
||||
lockType);
|
||||
handler.parseExtraInfoString(tmpCt.getExtraInfo());
|
||||
if (handler.locksMatch()
|
||||
&& (handler.getLockCount() > 0)) {
|
||||
ct = tmpCt;
|
||||
ct.setLockHandler(handler);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the last execution time for the detail's lock.
|
||||
*
|
||||
* @param details
|
||||
* @param lockType
|
||||
* @return true when update successful
|
||||
*/
|
||||
private boolean updateTime(String name, String details, LockType lockType) {
|
||||
ClusterTask ct = findCluster(name, details, lockType);
|
||||
if (ct != null) {
|
||||
if (ClusterLockUtils.updateLockTime(ct.getId().getName(), ct
|
||||
.getId().getDetails(), System.currentTimeMillis())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.edex.database.plugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.raytheon.uf.common.dataplugin.PluginDataObject;
|
||||
import com.raytheon.uf.common.dataplugin.PluginException;
|
||||
import com.raytheon.uf.common.dataplugin.annotations.DataURIUtil;
|
||||
import com.raytheon.uf.edex.database.DataAccessLayerException;
|
||||
import com.raytheon.uf.edex.database.query.DatabaseQuery;
|
||||
|
||||
/**
|
||||
* Utilities related to dataURIs and their corresponding database tables.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 21, 2014 2060 njensen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author njensen
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class DataURIDatabaseUtil {
|
||||
|
||||
private DataURIDatabaseUtil() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for the existence in the database of a PluginDataObject that
|
||||
* matches the argument. The check for existence is based on if the dataURI
|
||||
* of the PluginDataObject matches.
|
||||
*
|
||||
* @param pdo
|
||||
* the PluginDataObject to check to see if its equivalent dataURI
|
||||
* is in the database
|
||||
* @return true if a matching dataURI was found, false otherwise
|
||||
* @throws PluginException
|
||||
*/
|
||||
public static boolean existingDataURI(PluginDataObject pdo)
|
||||
throws PluginException {
|
||||
PluginDao dao = PluginFactory.getInstance().getPluginDao(
|
||||
pdo.getPluginName());
|
||||
DatabaseQuery dbQuery = new DatabaseQuery(pdo.getClass());
|
||||
Map<String, Object> dataUriFields = DataURIUtil.createDataURIMap(pdo);
|
||||
for (Map.Entry<String, Object> field : dataUriFields.entrySet()) {
|
||||
String fieldName = field.getKey();
|
||||
// ignore pluginName
|
||||
if (!PluginDataObject.PLUGIN_NAME_ID.equals(fieldName)) {
|
||||
dbQuery.addQueryParam(field.getKey(), field.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
List<?> list = dao.queryByCriteria(dbQuery);
|
||||
return (list != null && !list.isEmpty());
|
||||
} catch (DataAccessLayerException e) {
|
||||
throw new PluginException("Error querying database", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,144 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.edex.esb.camel.context;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
|
||||
import com.raytheon.uf.common.util.SystemUtil;
|
||||
import com.raytheon.uf.edex.database.cluster.ClusterLockUtils;
|
||||
import com.raytheon.uf.edex.database.cluster.ClusterTask;
|
||||
|
||||
/**
|
||||
* Implementation of {@link IContextStateManager} that handles clustered
|
||||
* contexts. Extends {@code DependencyContextStateManager} to allow for
|
||||
* clustered contexts to work with dependencies also.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 10, 2014 2726 rjpeter Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ClusteredContextStateManager extends DependencyContextStateManager {
|
||||
|
||||
/**
|
||||
* Name field for cluster task.
|
||||
*/
|
||||
private static final String taskName = "ClusteredContext";
|
||||
|
||||
/**
|
||||
* Field for extra-info to designate this host.
|
||||
*/
|
||||
private final String myName;
|
||||
|
||||
/**
|
||||
* Constructor that takes an {@code ExecutorService}. The
|
||||
* {@code ExecutorService} is used for starting/stopping dependent contexts.
|
||||
*
|
||||
* @param service
|
||||
*/
|
||||
public ClusteredContextStateManager(ExecutorService service) {
|
||||
super(service);
|
||||
myName = SystemUtil.getHostName() + ":"
|
||||
+ System.getProperty("edex.run.mode");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@code ClusterLock} details field.
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
protected static String getLockDetails(CamelContext context) {
|
||||
return context.getName() + ClusterLockUtils.CLUSTER_SUFFIX;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.uf.edex.esb.camel.context.DependencyContextStateManager#
|
||||
* isContextStartable(org.apache.camel.CamelContext)
|
||||
*/
|
||||
@Override
|
||||
public boolean isContextStartable(CamelContext context) throws Exception {
|
||||
boolean canStartContext = super.isContextStartable(context);
|
||||
|
||||
/*
|
||||
* Check cluster lock if we can start the context or if context is
|
||||
* already started in case we need to update the cluster lock.
|
||||
*/
|
||||
if (canStartContext || context.getStatus().isStarted()) {
|
||||
ClusterTask lock = ClusterLockUtils.lock(taskName,
|
||||
getLockDetails(context), myName, ContextManager
|
||||
.getInstance().getTimeOutMillis(), false);
|
||||
|
||||
switch (lock.getLockState()) {
|
||||
case ALREADY_RUNNING:
|
||||
// check if we already have lock
|
||||
canStartContext = lock.getExtraInfo().equals(myName);
|
||||
if (canStartContext) {
|
||||
// update the lock time
|
||||
ClusterLockUtils
|
||||
.updateLockTime(taskName, getLockDetails(context),
|
||||
System.currentTimeMillis());
|
||||
}
|
||||
break;
|
||||
case SUCCESSFUL:
|
||||
canStartContext = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
canStartContext = false;
|
||||
}
|
||||
}
|
||||
|
||||
return canStartContext;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.uf.edex.esb.camel.context.DependencyContextStateManager#
|
||||
* stopContext(org.apache.camel.CamelContext)
|
||||
*/
|
||||
@Override
|
||||
public boolean stopContext(CamelContext context) throws Exception {
|
||||
// on stop, unlock the cluster lock if we own it
|
||||
String contextName = context.getName()
|
||||
+ ClusterLockUtils.CLUSTER_SUFFIX;
|
||||
ClusterTask lock = ClusterLockUtils.lookupLock(taskName, contextName);
|
||||
if (lock.getExtraInfo().equals(myName) && lock.isRunning()) {
|
||||
ClusterLockUtils.unlock(taskName, contextName);
|
||||
}
|
||||
|
||||
return super.stopContext(context);
|
||||
}
|
||||
}
|
|
@ -1,225 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.edex.esb.camel.context;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.Route;
|
||||
|
||||
import com.raytheon.uf.common.util.Pair;
|
||||
import com.raytheon.uf.edex.core.EdexException;
|
||||
|
||||
/**
|
||||
* Contains all known contexts and parsed data about the contexts.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 10, 2014 2726 rjpeter Initial creation.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ContextData {
|
||||
private final List<CamelContext> contexts;
|
||||
|
||||
private final Map<String, Route> consumerRouteMapping;
|
||||
|
||||
private final Map<String, String> routeIdUriMapping;
|
||||
|
||||
/**
|
||||
* Pulls the direct-vm:name, vm:name, queue:name, topic:name section from
|
||||
* the endpoint URI.
|
||||
*/
|
||||
private static final Pattern endpointUriParsePattern = Pattern
|
||||
.compile("([^:]+)://([^?]+)");
|
||||
|
||||
/**
|
||||
* Parses passed contexts for route and endpoint data about all contexts.
|
||||
*
|
||||
* @param contexts
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public ContextData(List<CamelContext> contexts)
|
||||
throws ConfigurationException {
|
||||
this.contexts = Collections.unmodifiableList(contexts);
|
||||
this.consumerRouteMapping = Collections
|
||||
.unmodifiableMap(generateRouteMappings(this.contexts));
|
||||
Map<String, String> idUriMapping = new HashMap<String, String>(
|
||||
consumerRouteMapping.size(), 1);
|
||||
for (CamelContext ctx : this.contexts) {
|
||||
for (Route route : ctx.getRoutes()) {
|
||||
idUriMapping.put(route.getId(), route.getEndpoint()
|
||||
.getEndpointUri());
|
||||
}
|
||||
}
|
||||
|
||||
this.routeIdUriMapping = Collections.unmodifiableMap(idUriMapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates an endpointName to {@code Route} mapping for the passed
|
||||
* {@code CamelContext}s.
|
||||
*
|
||||
* @return
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
protected static Map<String, Route> generateRouteMappings(
|
||||
List<CamelContext> contexts) throws ConfigurationException {
|
||||
Map<String, Route> routeMapping = new HashMap<String, Route>(
|
||||
contexts.size() * 2, 1);
|
||||
|
||||
// populate the consumer definitions
|
||||
for (CamelContext context : contexts) {
|
||||
List<Route> routes = context.getRoutes();
|
||||
if ((routes != null) && (routes.size() > 0)) {
|
||||
for (Route route : routes) {
|
||||
String uri = route.getEndpoint().getEndpointUri();
|
||||
Pair<String, String> typeAndName = getEndpointTypeAndName(uri);
|
||||
if (typeAndName != null) {
|
||||
String endpointName = typeAndName.getSecond();
|
||||
|
||||
Route prev = routeMapping.put(endpointName, route);
|
||||
if ((prev != null)
|
||||
&& !endpointName.startsWith("topic:")) {
|
||||
throw new ConfigurationException(
|
||||
"Two contexts listen to the same endpoint name ["
|
||||
+ endpointName
|
||||
+ "]. ContextManager cannot handle this situation. Double check configuration. Conflicting contexts ["
|
||||
+ prev.getRouteContext()
|
||||
.getCamelContext()
|
||||
.getName() + "] and ["
|
||||
+ context.getName() + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return routeMapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the known contexts.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<CamelContext> getContexts() {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses URI for component type and endpoint name.
|
||||
*
|
||||
* @param uri
|
||||
* @return
|
||||
*/
|
||||
public static Pair<String, String> getEndpointTypeAndName(String uri) {
|
||||
Pair<String, String> rval = null;
|
||||
Matcher m = endpointUriParsePattern.matcher(uri);
|
||||
|
||||
if (m.find()) {
|
||||
String endpointType = m.group(1);
|
||||
String endpointName = m.group(2);
|
||||
rval = new Pair<String, String>(endpointType, endpointName);
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans the camel context and associated routes. Groups the routes by
|
||||
* consumer type.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<String, List<Route>> getContextRoutesByEndpointType()
|
||||
throws ConfigurationException {
|
||||
Map<String, List<Route>> routesByType = new HashMap<String, List<Route>>();
|
||||
for (CamelContext context : contexts) {
|
||||
List<Route> routes = context.getRoutes();
|
||||
if ((routes != null) && (routes.size() > 0)) {
|
||||
for (Route route : routes) {
|
||||
String uri = route.getEndpoint().getEndpointUri();
|
||||
Pair<String, String> typeAndName = getEndpointTypeAndName(uri);
|
||||
String type = typeAndName.getFirst();
|
||||
List<Route> routesForType = routesByType.get(type);
|
||||
if (routesForType == null) {
|
||||
routesForType = new LinkedList<Route>();
|
||||
routesByType.put(type, routesForType);
|
||||
}
|
||||
routesForType.add(route);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return routesByType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the uri for the consumer endpoint of the route with the specified
|
||||
* routeId.
|
||||
*
|
||||
* @param routeId
|
||||
* @return
|
||||
* @throws EdexException
|
||||
*/
|
||||
public String getEndpointUriForRouteId(String routeId) throws EdexException {
|
||||
String uri = routeIdUriMapping.get(routeId);
|
||||
if (uri == null) {
|
||||
throw new EdexException("Route id " + routeId
|
||||
+ " not found. Check loaded spring configurations.");
|
||||
}
|
||||
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the route for the endpoint with the passed name as returned from
|
||||
* getEndpointTypeAndName().
|
||||
*
|
||||
* @param endpointName
|
||||
* @return
|
||||
* @throws EdexException
|
||||
*/
|
||||
public Route getRouteForEndpointName(String endpointName)
|
||||
throws EdexException {
|
||||
Route route = consumerRouteMapping.get(endpointName);
|
||||
if (route == null) {
|
||||
throw new EdexException("Endpoint " + endpointName
|
||||
+ " not found. Check loaded spring configurations.");
|
||||
}
|
||||
|
||||
return route;
|
||||
}
|
||||
}
|
|
@ -1,268 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.edex.esb.camel.context;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.Endpoint;
|
||||
import org.apache.camel.Route;
|
||||
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.util.Pair;
|
||||
|
||||
/**
|
||||
* Contains context dependency mappings.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 26, 2014 2726 rjpeter Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ContextDependencyMapping {
|
||||
/**
|
||||
* Endpoint types that should be tracked for dependency mapping
|
||||
*/
|
||||
protected static final Set<String> DEPENDENCY_ENDPOINT_TYPES;
|
||||
|
||||
static {
|
||||
/*
|
||||
* Endpoint types that are used for inner context routing. If we add
|
||||
* other inner jvm routing types, they should be added here.
|
||||
*/
|
||||
Set<String> types = new HashSet<String>(8);
|
||||
types.add("vm");
|
||||
types.add("direct-vm");
|
||||
types.add("seda");
|
||||
types.add("jmx");
|
||||
types.add("guava-eventbus");
|
||||
DEPENDENCY_ENDPOINT_TYPES = Collections.unmodifiableSet(types);
|
||||
}
|
||||
|
||||
/**
|
||||
* The dependency mappings.
|
||||
*/
|
||||
protected final Map<CamelContext, DependencyNode> dependencyMapping;
|
||||
|
||||
/**
|
||||
* Populates the dependency mappings for all camel contexts.
|
||||
* {@code suppressExceptions} can be used to differentiate between
|
||||
* startup/shutdown conditions to allow the map to be populated regardless
|
||||
* of detected issues.
|
||||
*
|
||||
* @param contextData
|
||||
* @param suppressExceptions
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public ContextDependencyMapping(ContextData contextData,
|
||||
boolean suppressExceptions) throws ConfigurationException {
|
||||
dependencyMapping = Collections
|
||||
.unmodifiableMap(populateDependencyMapping(contextData,
|
||||
suppressExceptions));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@code IUFStatusHandler}. Not cached as rarely used.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static IUFStatusHandler getHandler() {
|
||||
return UFStatus.getHandler(ContextDependencyMapping.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dependency mappings per context. The dependency mapping is only for
|
||||
* internal vm types that have a direct dependency. Indirect dependency via
|
||||
* a JMS queue for example is not returned/enforced.
|
||||
*
|
||||
* @param contextData
|
||||
* @param suppressExceptions
|
||||
* Done in a shutdown scenario to get the dependencyMapping as
|
||||
* close as possible.
|
||||
*/
|
||||
protected static Map<CamelContext, DependencyNode> populateDependencyMapping(
|
||||
ContextData contextData, boolean suppressExceptions)
|
||||
throws ConfigurationException {
|
||||
List<CamelContext> contexts = contextData.getContexts();
|
||||
Map<CamelContext, DependencyNode> dependencyMapping = new LinkedHashMap<CamelContext, DependencyNode>(
|
||||
contexts.size());
|
||||
|
||||
// set up dependency nodes for internal types
|
||||
Map<String, CamelContext> consumesFrom = new HashMap<String, CamelContext>();
|
||||
Map<String, List<CamelContext>> producesTo = new HashMap<String, List<CamelContext>>();
|
||||
Set<String> consumers = new HashSet<String>();
|
||||
|
||||
// scan for consuming and producing internal endpoints
|
||||
for (CamelContext context : contexts) {
|
||||
dependencyMapping.put(context, new DependencyNode(context));
|
||||
consumers.clear();
|
||||
List<Route> routes = context.getRoutes();
|
||||
if ((routes != null) && (routes.size() > 0)) {
|
||||
for (Route route : routes) {
|
||||
String uri = route.getEndpoint().getEndpointUri();
|
||||
Pair<String, String> typeAndName = ContextData
|
||||
.getEndpointTypeAndName(uri);
|
||||
if ((typeAndName != null)
|
||||
&& DEPENDENCY_ENDPOINT_TYPES.contains(typeAndName
|
||||
.getFirst())) {
|
||||
String endpointName = typeAndName.getSecond();
|
||||
consumers.add(endpointName);
|
||||
|
||||
/*
|
||||
* Internal types don't support a fanout type policy
|
||||
* where multiple routes can listen to the same
|
||||
* endpoint.
|
||||
*/
|
||||
CamelContext prev = consumesFrom.put(endpointName,
|
||||
context);
|
||||
if (prev != null) {
|
||||
String msg = "Two contexts listen to the same internal endpoint ["
|
||||
+ endpointName
|
||||
+ "]. ContextManager cannot handle this situation. Double check configuration. Conflicting contexts ["
|
||||
+ prev.getName()
|
||||
+ "] and ["
|
||||
+ context.getName() + "]";
|
||||
if (suppressExceptions) {
|
||||
getHandler().error(msg);
|
||||
} else {
|
||||
throw new ConfigurationException(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collection<Endpoint> endpoints = context.getEndpoints();
|
||||
if ((endpoints != null) && (endpoints.size() > 0)) {
|
||||
for (Endpoint ep : endpoints) {
|
||||
String uri = ep.getEndpointUri();
|
||||
Pair<String, String> typeAndName = ContextData
|
||||
.getEndpointTypeAndName(uri);
|
||||
if ((typeAndName != null)
|
||||
&& DEPENDENCY_ENDPOINT_TYPES.contains(typeAndName
|
||||
.getFirst())) {
|
||||
String endpointName = typeAndName.getSecond();
|
||||
if (!consumers.contains(endpointName)) {
|
||||
List<CamelContext> producerCtxs = producesTo
|
||||
.get(endpointName);
|
||||
if (producerCtxs == null) {
|
||||
producerCtxs = new LinkedList<CamelContext>();
|
||||
producesTo.put(endpointName, producerCtxs);
|
||||
}
|
||||
producerCtxs.add(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// setup dependencies for internal routes
|
||||
for (Map.Entry<String, List<CamelContext>> producersEntry : producesTo
|
||||
.entrySet()) {
|
||||
String endpoint = producersEntry.getKey();
|
||||
CamelContext consumer = consumesFrom.get(endpoint);
|
||||
List<CamelContext> producers = producersEntry.getValue();
|
||||
|
||||
if (consumer == null) {
|
||||
StringBuilder msg = new StringBuilder(200);
|
||||
msg.append("Internal Routing Endpoint [")
|
||||
.append(endpoint)
|
||||
.append("] has no defined consumers. This is endpoint is used in contexts [");
|
||||
Iterator<CamelContext> producerIter = producers.iterator();
|
||||
|
||||
while (producerIter.hasNext()) {
|
||||
CamelContext producer = producerIter.next();
|
||||
msg.append(producer.getName());
|
||||
|
||||
if (producerIter.hasNext()) {
|
||||
msg.append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
msg.append("]");
|
||||
if (suppressExceptions) {
|
||||
getHandler().error(msg.toString());
|
||||
} else {
|
||||
throw new ConfigurationException(msg.toString());
|
||||
}
|
||||
} else {
|
||||
DependencyNode consumerNode = dependencyMapping.get(consumer);
|
||||
for (CamelContext producer : producers) {
|
||||
DependencyNode producerNode = dependencyMapping
|
||||
.get(producer);
|
||||
consumerNode.addDependentNode(producerNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
return dependencyMapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contexts that depend upon the passed context to work. If the
|
||||
* passed context is unknown null will be returned.
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public Set<CamelContext> getDependentContexts(CamelContext context) {
|
||||
DependencyNode dNode = dependencyMapping.get(context);
|
||||
if (dNode == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return dNode.getDependentContexts();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contexts that the passed context requires to be running to work.
|
||||
* If the passed context is unknown null will be returned.
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public Set<CamelContext> getRequiredContexts(CamelContext context) {
|
||||
DependencyNode dNode = dependencyMapping.get(context);
|
||||
if (dNode == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return dNode.getRequiredContexts();
|
||||
}
|
||||
}
|
|
@ -1,215 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.edex.esb.camel.context;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.Route;
|
||||
import org.apache.camel.ServiceStatus;
|
||||
|
||||
import com.raytheon.uf.edex.core.IContextStateProcessor;
|
||||
|
||||
/**
|
||||
* Implementation of IContextStateManager that does basic validation of context
|
||||
* status as well as handling IContextStateProcessor for startup/shutdown of
|
||||
* contexts.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 10, 2014 2726 rjpeter Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
public class DefaultContextStateManager implements IContextStateManager {
|
||||
private static final Set<ServiceStatus> STARTABLE_STATES = EnumSet.of(
|
||||
ServiceStatus.Stopped, ServiceStatus.Suspended,
|
||||
ServiceStatus.Suspending);
|
||||
|
||||
private static final Set<ServiceStatus> SUSPENDABLE_STATES = EnumSet.of(
|
||||
ServiceStatus.Starting, ServiceStatus.Started);
|
||||
|
||||
private static final Set<ServiceStatus> STOPPABLE_STATES = EnumSet.of(
|
||||
ServiceStatus.Starting, ServiceStatus.Started,
|
||||
ServiceStatus.Suspending, ServiceStatus.Suspended);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.uf.edex.esb.camel.context.IContextStateManager#
|
||||
* isContextStartable(org.apache.camel.CamelContext)
|
||||
*/
|
||||
@Override
|
||||
public boolean isContextStartable(CamelContext context) throws Exception {
|
||||
ServiceStatus status = context.getStatus();
|
||||
return STARTABLE_STATES.contains(status)
|
||||
|| (status.isStarted() && !context.isAutoStartup());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.uf.edex.esb.camel.context.IContextStateManager#startContext
|
||||
* (org.apache.camel.CamelContext)
|
||||
*/
|
||||
@Override
|
||||
public boolean startContext(CamelContext context) throws Exception {
|
||||
ServiceStatus status = context.getStatus();
|
||||
|
||||
boolean rval = status.isStarted();
|
||||
if (rval && !context.isAutoStartup()) {
|
||||
for (Route route : context.getRoutes()) {
|
||||
rval &= context.getRouteStatus(route.getId()).isStarted();
|
||||
}
|
||||
}
|
||||
|
||||
if (!rval) {
|
||||
IContextStateProcessor processor = ContextManager.getInstance()
|
||||
.getStateProcessor(context);
|
||||
if (processor != null) {
|
||||
processor.preStart();
|
||||
}
|
||||
|
||||
context.start();
|
||||
rval = context.getStatus().isStarted();
|
||||
|
||||
/*
|
||||
* if a context has autoStartup = false, all of its routes are
|
||||
* started on the second time context.start is called, adding route
|
||||
* check for future proofing just in case.
|
||||
*/
|
||||
if (!context.isAutoStartup()) {
|
||||
for (Route route : context.getRoutes()) {
|
||||
rval &= startRoute(route);
|
||||
}
|
||||
|
||||
/*
|
||||
* clear the auto start up flag since its an initial condition
|
||||
* only
|
||||
*/
|
||||
context.setAutoStartup(true);
|
||||
}
|
||||
|
||||
if (processor != null) {
|
||||
processor.postStart();
|
||||
}
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.uf.edex.esb.camel.context.IContextStateManager#startRoute
|
||||
* (org.apache.camel.Route)
|
||||
*/
|
||||
@Override
|
||||
public boolean startRoute(Route route) throws Exception {
|
||||
String routeId = route.getId();
|
||||
CamelContext ctx = route.getRouteContext().getCamelContext();
|
||||
ServiceStatus status = ctx.getRouteStatus(routeId);
|
||||
if (STARTABLE_STATES.contains(status)) {
|
||||
ctx.startRoute(routeId);
|
||||
status = ctx.getRouteStatus(routeId);
|
||||
}
|
||||
|
||||
return status.isStarted();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.uf.edex.esb.camel.context.IContextStateManager#
|
||||
* isContextStoppable (org.apache.camel.CamelContext)
|
||||
*/
|
||||
@Override
|
||||
public boolean isContextStoppable(CamelContext context) throws Exception {
|
||||
ServiceStatus status = context.getStatus();
|
||||
boolean shuttingDown = ContextManager.getInstance().isShuttingDown();
|
||||
return (shuttingDown && STOPPABLE_STATES.contains(status))
|
||||
|| (!shuttingDown && SUSPENDABLE_STATES.contains(status));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.uf.edex.esb.camel.context.IContextStateManager#stopContext
|
||||
* (org.apache.camel.CamelContext)
|
||||
*/
|
||||
@Override
|
||||
public boolean stopContext(CamelContext context) throws Exception {
|
||||
ServiceStatus status = context.getStatus();
|
||||
if (isContextStoppable(context)) {
|
||||
IContextStateProcessor processor = ContextManager.getInstance()
|
||||
.getStateProcessor(context);
|
||||
if (processor != null) {
|
||||
processor.preStop();
|
||||
}
|
||||
|
||||
// a context will automatically stop all its routes
|
||||
if (ContextManager.getInstance().isShuttingDown()) {
|
||||
context.stop();
|
||||
} else {
|
||||
context.suspend();
|
||||
}
|
||||
|
||||
if (processor != null) {
|
||||
processor.postStop();
|
||||
}
|
||||
|
||||
status = context.getStatus();
|
||||
}
|
||||
|
||||
return status.isStopped();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.uf.edex.esb.camel.context.IContextStateManager#stopRoute
|
||||
* (org.apache.camel.Route)
|
||||
*/
|
||||
@Override
|
||||
public boolean stopRoute(Route route) throws Exception {
|
||||
String routeId = route.getId();
|
||||
CamelContext ctx = route.getRouteContext().getCamelContext();
|
||||
ServiceStatus status = ctx.getRouteStatus(routeId);
|
||||
if (STOPPABLE_STATES.contains(status)) {
|
||||
ctx.stopRoute(routeId);
|
||||
status = ctx.getRouteStatus(routeId);
|
||||
}
|
||||
|
||||
return status.isStopped();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,229 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.edex.esb.camel.context;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.Route;
|
||||
|
||||
/**
|
||||
* Implementation of IContextStateManager that handles dependencies between
|
||||
* contexts so that contexts start/stop in the correct order. Can be given an
|
||||
* ExecutorService to use to start/stop dependent contexts.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 10, 2014 2726 rjpeter Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
public class DependencyContextStateManager extends DefaultContextStateManager {
|
||||
|
||||
/**
|
||||
* Service to use to start/stop dependent contexts. If null, context
|
||||
* processing will happen on current thread.
|
||||
*/
|
||||
protected final ExecutorService service;
|
||||
|
||||
public DependencyContextStateManager() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public DependencyContextStateManager(ExecutorService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.uf.edex.esb.camel.context.DefaultContextStateManager#
|
||||
* isContextStartable(org.apache.camel.CamelContext)
|
||||
*/
|
||||
@Override
|
||||
public boolean isContextStartable(CamelContext context) throws Exception {
|
||||
if (!super.isContextStartable(context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Set<CamelContext> requiredContexts = ContextManager.getInstance()
|
||||
.getDependencyMapping(false).getRequiredContexts(context);
|
||||
|
||||
if (requiredContexts != null) {
|
||||
for (CamelContext rContext : requiredContexts) {
|
||||
if (!rContext.getStatus().isStarted()) {
|
||||
return false;
|
||||
} else {
|
||||
for (Route rRoute : rContext.getRoutes()) {
|
||||
if (!rContext.getRouteStatus(rRoute.getId())
|
||||
.isStarted()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.uf.edex.esb.camel.context.DefaultContextStateManager#
|
||||
* startContext(org.apache.camel.CamelContext)
|
||||
*/
|
||||
@Override
|
||||
public boolean startContext(CamelContext context) throws Exception {
|
||||
boolean rval = super.startContext(context);
|
||||
ContextManager ctxMgr = ContextManager.getInstance();
|
||||
|
||||
if (rval) {
|
||||
Set<CamelContext> dContexts = ctxMgr.getDependencyMapping(false)
|
||||
.getDependentContexts(context);
|
||||
if (dContexts != null) {
|
||||
List<Future<Boolean>> callbacks = null;
|
||||
|
||||
for (final CamelContext dCtx : dContexts) {
|
||||
final IContextStateManager stateMgr = ctxMgr
|
||||
.getStateManager(dCtx);
|
||||
if (stateMgr.isContextStartable(dCtx)) {
|
||||
if (service != null) {
|
||||
if (callbacks == null) {
|
||||
callbacks = new LinkedList<Future<Boolean>>();
|
||||
}
|
||||
|
||||
callbacks.add(service
|
||||
.submit(new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
return stateMgr.startContext(dCtx);
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
stateMgr.startContext(dCtx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (callbacks != null) {
|
||||
for (Future<Boolean> callback : callbacks) {
|
||||
rval &= callback.get().booleanValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.uf.edex.esb.camel.context.DefaultContextStateManager#
|
||||
* isContextStoppable(org.apache.camel.CamelContext)
|
||||
*/
|
||||
@Override
|
||||
public boolean isContextStoppable(CamelContext context) throws Exception {
|
||||
if (!super.isContextStoppable(context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Set<CamelContext> dContexts = ContextManager.getInstance()
|
||||
.getDependencyMapping(true).getDependentContexts(context);
|
||||
|
||||
if (dContexts != null) {
|
||||
for (CamelContext dContext : dContexts) {
|
||||
/*
|
||||
* only need to check if the context has stopped, can't have a
|
||||
* stopped context with started routes.
|
||||
*/
|
||||
if (!dContext.getStatus().isStopped()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.uf.edex.esb.camel.context.DefaultContextStateManager#stopContext
|
||||
* (org.apache.camel.CamelContext)
|
||||
*/
|
||||
@Override
|
||||
public boolean stopContext(CamelContext context) throws Exception {
|
||||
boolean rval = super.stopContext(context);
|
||||
ContextManager ctxMgr = ContextManager.getInstance();
|
||||
|
||||
if (rval) {
|
||||
Set<CamelContext> rContexts = ctxMgr.getDependencyMapping(true)
|
||||
.getRequiredContexts(context);
|
||||
if (rContexts != null) {
|
||||
List<Future<Boolean>> callbacks = null;
|
||||
|
||||
for (final CamelContext rCtx : rContexts) {
|
||||
final IContextStateManager stateMgr = ctxMgr
|
||||
.getStateManager(rCtx);
|
||||
if (stateMgr.isContextStoppable(rCtx)) {
|
||||
if (service != null) {
|
||||
if (callbacks == null) {
|
||||
callbacks = new LinkedList<Future<Boolean>>();
|
||||
}
|
||||
|
||||
callbacks.add(service
|
||||
.submit(new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
return stateMgr.stopContext(rCtx);
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
stateMgr.stopContext(rCtx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (callbacks != null) {
|
||||
for (Future<Boolean> callback : callbacks) {
|
||||
rval &= callback.get().booleanValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.edex.esb.camel.context;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.Endpoint;
|
||||
import org.apache.camel.Route;
|
||||
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.util.Pair;
|
||||
|
||||
/**
|
||||
* Class to map a context to its required and dependent contexts.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 10, 2014 2726 rjpeter Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
public class DependencyNode {
|
||||
private final CamelContext context;
|
||||
|
||||
/**
|
||||
* Contexts required by this context.
|
||||
*/
|
||||
private final Set<CamelContext> requiredContexs = new HashSet<CamelContext>();
|
||||
|
||||
/**
|
||||
* Contexts that depend on this context.
|
||||
*/
|
||||
private final Set<CamelContext> dependentContexts = new HashSet<CamelContext>();
|
||||
|
||||
public DependencyNode(CamelContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a node who is dependent on this node. Applies linking in both
|
||||
* directions.
|
||||
*
|
||||
* @param dNode
|
||||
*/
|
||||
public void addDependentNode(DependencyNode dNode) {
|
||||
if (!requiredContexs.contains(dNode.context)) {
|
||||
dependentContexts.add(dNode.context);
|
||||
dNode.requiredContexs.add(context);
|
||||
} else {
|
||||
StringBuilder msg = new StringBuilder(300);
|
||||
msg.append("Circular CamelContext dependency detected between ")
|
||||
.append(context.getName())
|
||||
.append(" and ")
|
||||
.append(dNode.context.getName())
|
||||
.append(". Removing dependency, startup/shutdown may be incorrect, verify configuration. ");
|
||||
addRouteData(context, msg);
|
||||
addRouteData(dNode.context, msg);
|
||||
UFStatus.getHandler(DependencyNode.class).warn(msg.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public CamelContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all contexts that this context requires to be running.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<CamelContext> getRequiredContexts() {
|
||||
return requiredContexs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all contexts that depend on this context to be running.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<CamelContext> getDependentContexts() {
|
||||
return dependentContexts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method for printing information about a context.
|
||||
*
|
||||
* @param ctx
|
||||
* @param builder
|
||||
*/
|
||||
private static void addRouteData(CamelContext ctx, StringBuilder builder) {
|
||||
builder.append("Context [").append(ctx.getName())
|
||||
.append("] consumes from [");
|
||||
Set<String> consumerEndpoints = new HashSet<String>();
|
||||
for (Route route : ctx.getRoutes()) {
|
||||
Endpoint endpoint = route.getEndpoint();
|
||||
String uri = endpoint.getEndpointUri();
|
||||
Pair<String, String> typeAndName = ContextData
|
||||
.getEndpointTypeAndName(uri);
|
||||
String name = typeAndName.getFirst() + ":"
|
||||
+ typeAndName.getSecond();
|
||||
builder.append(name).append(", ");
|
||||
consumerEndpoints.add(name);
|
||||
}
|
||||
builder.delete(builder.length() - 2, builder.length());
|
||||
builder.append("] and produces to [");
|
||||
for (Endpoint endpoint : ctx.getEndpoints()) {
|
||||
String uri = endpoint.getEndpointUri();
|
||||
Pair<String, String> typeAndName = ContextData
|
||||
.getEndpointTypeAndName(uri);
|
||||
String name = typeAndName.getFirst() + ":"
|
||||
+ typeAndName.getSecond();
|
||||
if (!consumerEndpoints.contains(name)) {
|
||||
builder.append(name).append(", ");
|
||||
}
|
||||
}
|
||||
builder.delete(builder.length() - 2, builder.length());
|
||||
builder.append("]. ");
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.edex.esb.camel.context;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.Route;
|
||||
|
||||
/**
|
||||
* Represents a way for managing a context for starting and stopping. Allows for
|
||||
* Context with different purposes to be handled independently of each other.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 10, 2014 2726 rjpeter Initial creation.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface IContextStateManager {
|
||||
/**
|
||||
* Is the {@code CamelContext} startable?
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public boolean isContextStartable(CamelContext context) throws Exception;
|
||||
|
||||
/**
|
||||
* Start the {@code CamelContext}.
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public boolean startContext(CamelContext context) throws Exception;
|
||||
|
||||
/**
|
||||
* Start the {@code Route}.
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public boolean startRoute(Route route) throws Exception;
|
||||
|
||||
/**
|
||||
* Is the {@code CamelContext} stoppable?
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public boolean isContextStoppable(CamelContext context) throws Exception;
|
||||
|
||||
/**
|
||||
* Stop the {@code CamelContext}.
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public boolean stopContext(CamelContext context) throws Exception;
|
||||
|
||||
/**
|
||||
* Stop the {@code Route}.
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public boolean stopRoute(Route route) throws Exception;
|
||||
}
|
Loading…
Add table
Reference in a new issue