repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
alexbirkett/android-cassowary-layout
library/src/main/java/no/agens/cassowarylayout/CassowaryLayout.java
// Path: library/src/main/java/no/agens/cassowarylayout/util/MeasureSpecUtils.java // public class MeasureSpecUtils { // public static String getModeAsString(int modeOrSpec) { // String modeAsString; // int mode = View.MeasureSpec.getMode(modeOrSpec); // if (mode == View.MeasureSpec.EXACTLY) { // modeAsString = "EXACTLY"; // } else if (mode == View.MeasureSpec.AT_MOST) { // modeAsString = "AT_MOST"; // } else if (mode == View.MeasureSpec.UNSPECIFIED) { // modeAsString = "UNSPECIFIED"; // } else { // modeAsString = "unknown mode " + modeOrSpec; // } // // return modeAsString; // } // } // // Path: library/src/main/java/no/agens/cassowarylayout/util/TimerUtil.java // public class TimerUtil { // public static long since(long since) { // return (System.nanoTime() - since) / 1000000; // } // }
import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import no.agens.cassowarylayout.util.MeasureSpecUtils; import no.agens.cassowarylayout.util.TimerUtil; import android.content.Context; import android.content.res.TypedArray; import android.os.Handler; import android.os.Looper; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.view.ViewGroup; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator;
this.aspectRatioHeightFactor = aspectRatioHeightFactor; } public void setChildPositionsFromCassowaryModel() { long timeBeforeSolve = System.nanoTime(); int count = getChildCount(); for (int i = 0; i < count; i++) { View child = getChildAt(i); if (child.getVisibility() != GONE) { int childId = child.getId(); Node node = getNodeById(childId); int x = (int) node.getLeft().value() + getPaddingLeft(); int y = (int) node.getTop().value() + getPaddingTop(); child.setX(x); child.setY(y); } } log("setChildPositionsFromCassowaryModel - took " + TimerUtil.since(timeBeforeSolve)); } @Override protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { long before = System.nanoTime(); log("onMeasure width " +
// Path: library/src/main/java/no/agens/cassowarylayout/util/MeasureSpecUtils.java // public class MeasureSpecUtils { // public static String getModeAsString(int modeOrSpec) { // String modeAsString; // int mode = View.MeasureSpec.getMode(modeOrSpec); // if (mode == View.MeasureSpec.EXACTLY) { // modeAsString = "EXACTLY"; // } else if (mode == View.MeasureSpec.AT_MOST) { // modeAsString = "AT_MOST"; // } else if (mode == View.MeasureSpec.UNSPECIFIED) { // modeAsString = "UNSPECIFIED"; // } else { // modeAsString = "unknown mode " + modeOrSpec; // } // // return modeAsString; // } // } // // Path: library/src/main/java/no/agens/cassowarylayout/util/TimerUtil.java // public class TimerUtil { // public static long since(long since) { // return (System.nanoTime() - since) / 1000000; // } // } // Path: library/src/main/java/no/agens/cassowarylayout/CassowaryLayout.java import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import no.agens.cassowarylayout.util.MeasureSpecUtils; import no.agens.cassowarylayout.util.TimerUtil; import android.content.Context; import android.content.res.TypedArray; import android.os.Handler; import android.os.Looper; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.view.ViewGroup; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; this.aspectRatioHeightFactor = aspectRatioHeightFactor; } public void setChildPositionsFromCassowaryModel() { long timeBeforeSolve = System.nanoTime(); int count = getChildCount(); for (int i = 0; i < count; i++) { View child = getChildAt(i); if (child.getVisibility() != GONE) { int childId = child.getId(); Node node = getNodeById(childId); int x = (int) node.getLeft().value() + getPaddingLeft(); int y = (int) node.getTop().value() + getPaddingTop(); child.setX(x); child.setY(y); } } log("setChildPositionsFromCassowaryModel - took " + TimerUtil.since(timeBeforeSolve)); } @Override protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { long before = System.nanoTime(); log("onMeasure width " +
MeasureSpecUtils.getModeAsString(widthMeasureSpec) + " " +
alexbirkett/android-cassowary-layout
library/src/main/java/no/agens/cassowarylayout/Node.java
// Path: library/src/main/java/no/agens/cassowarylayout/util/CassowaryUtil.java // public class CassowaryUtil { // // public static Constraint createWeakEqualityConstraint() { // return new Constraint(new Expression(null, -1.0, 0), Strength.WEAK); // } // // public static Constraint createWeakInequalityConstraint(Variable variable, Constraint.Operator op, double value) { // Expression expression = new Expression(value); // return new Constraint(variable, op, expression, Strength.STRONG); // } // // public static void updateConstraint(Constraint constraint, Variable variable, double value) { // Expression expression = constraint.expression(); // expression.set_constant(value); // expression.setVariable(variable, -1); // } // // // public static Constraint createOrUpdateLeqInequalityConstraint(Variable variable, Constraint constraint, double value, SimplexSolver solver) { // if (constraint != null) { // double currentValue = constraint.expression().constant(); // // This will not detect if the variable or strength has changed. // if (currentValue != value) { // try { // solver.removeConstraint(constraint); // } catch (ConstraintNotFound constraintNotFound) { // constraintNotFound.printStackTrace(); // } // constraint = null; // } // } // // if (constraint == null) { // constraint = new Constraint(variable, Constraint.Operator.LEQ, value, Strength.STRONG); // solver.addConstraint(constraint); // } // // return constraint; // } // // public static Constraint createOrUpdateLinearEquationConstraint(Variable variable, Constraint constraint, double value, SimplexSolver solver) { // if (constraint != null) { // double currentValue = constraint.expression().constant(); // // This will not detect if the variable, strength or operation has changed // if (currentValue != value) { // try { // solver.removeConstraint(constraint); // } catch (ConstraintNotFound constraintNotFound) { // constraintNotFound.printStackTrace(); // } // constraint = null; // } // } // // if (constraint == null) { // constraint = new Constraint(variable, Constraint.Operator.EQ, value, Strength.STRONG); // solver.addConstraint(constraint); // } // // return constraint; // } // } // // Path: library/src/main/java/no/agens/cassowarylayout/util/TimerUtil.java // public class TimerUtil { // public static long since(long since) { // return (System.nanoTime() - since) / 1000000; // } // }
import org.pybee.cassowary.Constraint; import org.pybee.cassowary.SimplexSolver; import org.pybee.cassowary.Variable; import android.util.Log; import java.util.HashMap; import no.agens.cassowarylayout.util.CassowaryUtil; import no.agens.cassowarylayout.util.TimerUtil;
return getVariable(WIDTH); } public Variable getBottom() { return getVariable(BOTTOM); } public Variable getRight() { return getVariable(RIGHT); } public Variable getCenterX() { return getVariable(CENTERX); } public Variable getCenterY() { return getVariable(CENTERY); } public void setIntrinsicWidth(int intrinsicWidth) { setVariableToValue(INTRINSIC_WIDTH, intrinsicWidth); } public void setIntrinsicHeight(int intrinsicHeight) { setVariableToValue(INTRINSIC_HEIGHT, intrinsicHeight); } public void setVariableToValue(String nameVariable, double value) { long timeBefore = System.nanoTime(); Constraint constraint = constraints.get(nameVariable);
// Path: library/src/main/java/no/agens/cassowarylayout/util/CassowaryUtil.java // public class CassowaryUtil { // // public static Constraint createWeakEqualityConstraint() { // return new Constraint(new Expression(null, -1.0, 0), Strength.WEAK); // } // // public static Constraint createWeakInequalityConstraint(Variable variable, Constraint.Operator op, double value) { // Expression expression = new Expression(value); // return new Constraint(variable, op, expression, Strength.STRONG); // } // // public static void updateConstraint(Constraint constraint, Variable variable, double value) { // Expression expression = constraint.expression(); // expression.set_constant(value); // expression.setVariable(variable, -1); // } // // // public static Constraint createOrUpdateLeqInequalityConstraint(Variable variable, Constraint constraint, double value, SimplexSolver solver) { // if (constraint != null) { // double currentValue = constraint.expression().constant(); // // This will not detect if the variable or strength has changed. // if (currentValue != value) { // try { // solver.removeConstraint(constraint); // } catch (ConstraintNotFound constraintNotFound) { // constraintNotFound.printStackTrace(); // } // constraint = null; // } // } // // if (constraint == null) { // constraint = new Constraint(variable, Constraint.Operator.LEQ, value, Strength.STRONG); // solver.addConstraint(constraint); // } // // return constraint; // } // // public static Constraint createOrUpdateLinearEquationConstraint(Variable variable, Constraint constraint, double value, SimplexSolver solver) { // if (constraint != null) { // double currentValue = constraint.expression().constant(); // // This will not detect if the variable, strength or operation has changed // if (currentValue != value) { // try { // solver.removeConstraint(constraint); // } catch (ConstraintNotFound constraintNotFound) { // constraintNotFound.printStackTrace(); // } // constraint = null; // } // } // // if (constraint == null) { // constraint = new Constraint(variable, Constraint.Operator.EQ, value, Strength.STRONG); // solver.addConstraint(constraint); // } // // return constraint; // } // } // // Path: library/src/main/java/no/agens/cassowarylayout/util/TimerUtil.java // public class TimerUtil { // public static long since(long since) { // return (System.nanoTime() - since) / 1000000; // } // } // Path: library/src/main/java/no/agens/cassowarylayout/Node.java import org.pybee.cassowary.Constraint; import org.pybee.cassowary.SimplexSolver; import org.pybee.cassowary.Variable; import android.util.Log; import java.util.HashMap; import no.agens.cassowarylayout.util.CassowaryUtil; import no.agens.cassowarylayout.util.TimerUtil; return getVariable(WIDTH); } public Variable getBottom() { return getVariable(BOTTOM); } public Variable getRight() { return getVariable(RIGHT); } public Variable getCenterX() { return getVariable(CENTERX); } public Variable getCenterY() { return getVariable(CENTERY); } public void setIntrinsicWidth(int intrinsicWidth) { setVariableToValue(INTRINSIC_WIDTH, intrinsicWidth); } public void setIntrinsicHeight(int intrinsicHeight) { setVariableToValue(INTRINSIC_HEIGHT, intrinsicHeight); } public void setVariableToValue(String nameVariable, double value) { long timeBefore = System.nanoTime(); Constraint constraint = constraints.get(nameVariable);
constraint = CassowaryUtil.createOrUpdateLinearEquationConstraint(getVariable(nameVariable), constraint, value, solver);
alexbirkett/android-cassowary-layout
library/src/main/java/no/agens/cassowarylayout/Node.java
// Path: library/src/main/java/no/agens/cassowarylayout/util/CassowaryUtil.java // public class CassowaryUtil { // // public static Constraint createWeakEqualityConstraint() { // return new Constraint(new Expression(null, -1.0, 0), Strength.WEAK); // } // // public static Constraint createWeakInequalityConstraint(Variable variable, Constraint.Operator op, double value) { // Expression expression = new Expression(value); // return new Constraint(variable, op, expression, Strength.STRONG); // } // // public static void updateConstraint(Constraint constraint, Variable variable, double value) { // Expression expression = constraint.expression(); // expression.set_constant(value); // expression.setVariable(variable, -1); // } // // // public static Constraint createOrUpdateLeqInequalityConstraint(Variable variable, Constraint constraint, double value, SimplexSolver solver) { // if (constraint != null) { // double currentValue = constraint.expression().constant(); // // This will not detect if the variable or strength has changed. // if (currentValue != value) { // try { // solver.removeConstraint(constraint); // } catch (ConstraintNotFound constraintNotFound) { // constraintNotFound.printStackTrace(); // } // constraint = null; // } // } // // if (constraint == null) { // constraint = new Constraint(variable, Constraint.Operator.LEQ, value, Strength.STRONG); // solver.addConstraint(constraint); // } // // return constraint; // } // // public static Constraint createOrUpdateLinearEquationConstraint(Variable variable, Constraint constraint, double value, SimplexSolver solver) { // if (constraint != null) { // double currentValue = constraint.expression().constant(); // // This will not detect if the variable, strength or operation has changed // if (currentValue != value) { // try { // solver.removeConstraint(constraint); // } catch (ConstraintNotFound constraintNotFound) { // constraintNotFound.printStackTrace(); // } // constraint = null; // } // } // // if (constraint == null) { // constraint = new Constraint(variable, Constraint.Operator.EQ, value, Strength.STRONG); // solver.addConstraint(constraint); // } // // return constraint; // } // } // // Path: library/src/main/java/no/agens/cassowarylayout/util/TimerUtil.java // public class TimerUtil { // public static long since(long since) { // return (System.nanoTime() - since) / 1000000; // } // }
import org.pybee.cassowary.Constraint; import org.pybee.cassowary.SimplexSolver; import org.pybee.cassowary.Variable; import android.util.Log; import java.util.HashMap; import no.agens.cassowarylayout.util.CassowaryUtil; import no.agens.cassowarylayout.util.TimerUtil;
public Variable getBottom() { return getVariable(BOTTOM); } public Variable getRight() { return getVariable(RIGHT); } public Variable getCenterX() { return getVariable(CENTERX); } public Variable getCenterY() { return getVariable(CENTERY); } public void setIntrinsicWidth(int intrinsicWidth) { setVariableToValue(INTRINSIC_WIDTH, intrinsicWidth); } public void setIntrinsicHeight(int intrinsicHeight) { setVariableToValue(INTRINSIC_HEIGHT, intrinsicHeight); } public void setVariableToValue(String nameVariable, double value) { long timeBefore = System.nanoTime(); Constraint constraint = constraints.get(nameVariable); constraint = CassowaryUtil.createOrUpdateLinearEquationConstraint(getVariable(nameVariable), constraint, value, solver); constraints.put(nameVariable, constraint);
// Path: library/src/main/java/no/agens/cassowarylayout/util/CassowaryUtil.java // public class CassowaryUtil { // // public static Constraint createWeakEqualityConstraint() { // return new Constraint(new Expression(null, -1.0, 0), Strength.WEAK); // } // // public static Constraint createWeakInequalityConstraint(Variable variable, Constraint.Operator op, double value) { // Expression expression = new Expression(value); // return new Constraint(variable, op, expression, Strength.STRONG); // } // // public static void updateConstraint(Constraint constraint, Variable variable, double value) { // Expression expression = constraint.expression(); // expression.set_constant(value); // expression.setVariable(variable, -1); // } // // // public static Constraint createOrUpdateLeqInequalityConstraint(Variable variable, Constraint constraint, double value, SimplexSolver solver) { // if (constraint != null) { // double currentValue = constraint.expression().constant(); // // This will not detect if the variable or strength has changed. // if (currentValue != value) { // try { // solver.removeConstraint(constraint); // } catch (ConstraintNotFound constraintNotFound) { // constraintNotFound.printStackTrace(); // } // constraint = null; // } // } // // if (constraint == null) { // constraint = new Constraint(variable, Constraint.Operator.LEQ, value, Strength.STRONG); // solver.addConstraint(constraint); // } // // return constraint; // } // // public static Constraint createOrUpdateLinearEquationConstraint(Variable variable, Constraint constraint, double value, SimplexSolver solver) { // if (constraint != null) { // double currentValue = constraint.expression().constant(); // // This will not detect if the variable, strength or operation has changed // if (currentValue != value) { // try { // solver.removeConstraint(constraint); // } catch (ConstraintNotFound constraintNotFound) { // constraintNotFound.printStackTrace(); // } // constraint = null; // } // } // // if (constraint == null) { // constraint = new Constraint(variable, Constraint.Operator.EQ, value, Strength.STRONG); // solver.addConstraint(constraint); // } // // return constraint; // } // } // // Path: library/src/main/java/no/agens/cassowarylayout/util/TimerUtil.java // public class TimerUtil { // public static long since(long since) { // return (System.nanoTime() - since) / 1000000; // } // } // Path: library/src/main/java/no/agens/cassowarylayout/Node.java import org.pybee.cassowary.Constraint; import org.pybee.cassowary.SimplexSolver; import org.pybee.cassowary.Variable; import android.util.Log; import java.util.HashMap; import no.agens.cassowarylayout.util.CassowaryUtil; import no.agens.cassowarylayout.util.TimerUtil; public Variable getBottom() { return getVariable(BOTTOM); } public Variable getRight() { return getVariable(RIGHT); } public Variable getCenterX() { return getVariable(CENTERX); } public Variable getCenterY() { return getVariable(CENTERY); } public void setIntrinsicWidth(int intrinsicWidth) { setVariableToValue(INTRINSIC_WIDTH, intrinsicWidth); } public void setIntrinsicHeight(int intrinsicHeight) { setVariableToValue(INTRINSIC_HEIGHT, intrinsicHeight); } public void setVariableToValue(String nameVariable, double value) { long timeBefore = System.nanoTime(); Constraint constraint = constraints.get(nameVariable); constraint = CassowaryUtil.createOrUpdateLinearEquationConstraint(getVariable(nameVariable), constraint, value, solver); constraints.put(nameVariable, constraint);
Log.d(LOG_TAG, "setVariableToValue name " + nameVariable + " value " + value + " took " + TimerUtil.since(timeBefore));
alexbirkett/android-cassowary-layout
library/src/main/java/no/agens/cassowarylayout/CassowaryModel.java
// Path: library/src/main/java/no/agens/cassowarylayout/util/DimensionParser.java // public class DimensionParser { // // private static Pattern pattern = Pattern.compile("^(wrapContent|matchParent)|(\\d+)(px|dp|sp|pt|in|mm)"); // // public static Double getDimension(String widthHeightString, Context context) { // // Double widthHeight = null; // // Matcher matcher = pattern.matcher(widthHeightString); // // matcher.find(); // // if (matcher.matches()) { // if (matcher.group(2) == null) { // widthHeight = (double)RelativeLayout.LayoutParams.MATCH_PARENT; // if ("wrapContent".equals(matcher.group(1))) { // widthHeight = (double)RelativeLayout.LayoutParams.WRAP_CONTENT; // } // } else { // String value = matcher.group(2); // String unit = matcher.group(3); // try { // widthHeight = (double)TypedValue.applyDimension(getUnitFromString(unit), Integer.parseInt(value), context.getResources().getDisplayMetrics()); // //widthHeight = Integer.parseInt(widthHeightString.substring(0, widthHeightString.)); // } catch (NumberFormatException e) { // // ignore // } // } // } // // return widthHeight; // // } // // private static int getUnitFromString(String unitString) { // // int unit = TypedValue.COMPLEX_UNIT_DIP; // if ("px".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_PX; // } else if ("dp".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_DIP; // } else if ("sp".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_SP; // } else if ("pt".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_PT; // } else if ("in".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_IN; // } else if ("mm".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_MM; // } // return unit; // } // } // // Path: library/src/main/java/no/agens/cassowarylayout/util/TimerUtil.java // public class TimerUtil { // public static long since(long since) { // return (System.nanoTime() - since) / 1000000; // } // }
import android.content.Context; import android.util.Log; import org.pybee.cassowary.Constraint; import org.pybee.cassowary.ConstraintNotFound; import org.pybee.cassowary.Expression; import org.pybee.cassowary.SimplexSolver; import org.pybee.cassowary.Variable; import java.util.HashMap; import no.agens.cassowarylayout.util.DimensionParser; import no.agens.cassowarylayout.util.TimerUtil;
package no.agens.cassowarylayout; /** * Created by alex on 01/11/14. */ public class CassowaryModel { private Context context; private static final String LOG_TAG = "CassowaryModel"; public CassowaryModel(Context context) { this.context = context; setupCassowary(); } private HashMap<String, ChildNode> nodes = new HashMap<String, ChildNode>(); private SimplexSolver solver = new SimplexSolver(); private ContainerNode containerNode = new ContainerNode(solver); private ConstraintParser.CassowaryVariableResolver cassowaryVariableResolver = new ConstraintParser.CassowaryVariableResolver() { @Override public Variable resolveVariable(String variableName) { return CassowaryModel.this.resolveVariable(variableName); } @Override public Expression resolveConstant(String constantName) { Expression expression = null; Double value; try { value = Double.parseDouble(constantName); } catch (NumberFormatException e) {
// Path: library/src/main/java/no/agens/cassowarylayout/util/DimensionParser.java // public class DimensionParser { // // private static Pattern pattern = Pattern.compile("^(wrapContent|matchParent)|(\\d+)(px|dp|sp|pt|in|mm)"); // // public static Double getDimension(String widthHeightString, Context context) { // // Double widthHeight = null; // // Matcher matcher = pattern.matcher(widthHeightString); // // matcher.find(); // // if (matcher.matches()) { // if (matcher.group(2) == null) { // widthHeight = (double)RelativeLayout.LayoutParams.MATCH_PARENT; // if ("wrapContent".equals(matcher.group(1))) { // widthHeight = (double)RelativeLayout.LayoutParams.WRAP_CONTENT; // } // } else { // String value = matcher.group(2); // String unit = matcher.group(3); // try { // widthHeight = (double)TypedValue.applyDimension(getUnitFromString(unit), Integer.parseInt(value), context.getResources().getDisplayMetrics()); // //widthHeight = Integer.parseInt(widthHeightString.substring(0, widthHeightString.)); // } catch (NumberFormatException e) { // // ignore // } // } // } // // return widthHeight; // // } // // private static int getUnitFromString(String unitString) { // // int unit = TypedValue.COMPLEX_UNIT_DIP; // if ("px".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_PX; // } else if ("dp".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_DIP; // } else if ("sp".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_SP; // } else if ("pt".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_PT; // } else if ("in".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_IN; // } else if ("mm".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_MM; // } // return unit; // } // } // // Path: library/src/main/java/no/agens/cassowarylayout/util/TimerUtil.java // public class TimerUtil { // public static long since(long since) { // return (System.nanoTime() - since) / 1000000; // } // } // Path: library/src/main/java/no/agens/cassowarylayout/CassowaryModel.java import android.content.Context; import android.util.Log; import org.pybee.cassowary.Constraint; import org.pybee.cassowary.ConstraintNotFound; import org.pybee.cassowary.Expression; import org.pybee.cassowary.SimplexSolver; import org.pybee.cassowary.Variable; import java.util.HashMap; import no.agens.cassowarylayout.util.DimensionParser; import no.agens.cassowarylayout.util.TimerUtil; package no.agens.cassowarylayout; /** * Created by alex on 01/11/14. */ public class CassowaryModel { private Context context; private static final String LOG_TAG = "CassowaryModel"; public CassowaryModel(Context context) { this.context = context; setupCassowary(); } private HashMap<String, ChildNode> nodes = new HashMap<String, ChildNode>(); private SimplexSolver solver = new SimplexSolver(); private ContainerNode containerNode = new ContainerNode(solver); private ConstraintParser.CassowaryVariableResolver cassowaryVariableResolver = new ConstraintParser.CassowaryVariableResolver() { @Override public Variable resolveVariable(String variableName) { return CassowaryModel.this.resolveVariable(variableName); } @Override public Expression resolveConstant(String constantName) { Expression expression = null; Double value; try { value = Double.parseDouble(constantName); } catch (NumberFormatException e) {
value = DimensionParser.getDimension(constantName, getContext());
alexbirkett/android-cassowary-layout
library/src/main/java/no/agens/cassowarylayout/CassowaryModel.java
// Path: library/src/main/java/no/agens/cassowarylayout/util/DimensionParser.java // public class DimensionParser { // // private static Pattern pattern = Pattern.compile("^(wrapContent|matchParent)|(\\d+)(px|dp|sp|pt|in|mm)"); // // public static Double getDimension(String widthHeightString, Context context) { // // Double widthHeight = null; // // Matcher matcher = pattern.matcher(widthHeightString); // // matcher.find(); // // if (matcher.matches()) { // if (matcher.group(2) == null) { // widthHeight = (double)RelativeLayout.LayoutParams.MATCH_PARENT; // if ("wrapContent".equals(matcher.group(1))) { // widthHeight = (double)RelativeLayout.LayoutParams.WRAP_CONTENT; // } // } else { // String value = matcher.group(2); // String unit = matcher.group(3); // try { // widthHeight = (double)TypedValue.applyDimension(getUnitFromString(unit), Integer.parseInt(value), context.getResources().getDisplayMetrics()); // //widthHeight = Integer.parseInt(widthHeightString.substring(0, widthHeightString.)); // } catch (NumberFormatException e) { // // ignore // } // } // } // // return widthHeight; // // } // // private static int getUnitFromString(String unitString) { // // int unit = TypedValue.COMPLEX_UNIT_DIP; // if ("px".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_PX; // } else if ("dp".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_DIP; // } else if ("sp".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_SP; // } else if ("pt".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_PT; // } else if ("in".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_IN; // } else if ("mm".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_MM; // } // return unit; // } // } // // Path: library/src/main/java/no/agens/cassowarylayout/util/TimerUtil.java // public class TimerUtil { // public static long since(long since) { // return (System.nanoTime() - since) / 1000000; // } // }
import android.content.Context; import android.util.Log; import org.pybee.cassowary.Constraint; import org.pybee.cassowary.ConstraintNotFound; import org.pybee.cassowary.Expression; import org.pybee.cassowary.SimplexSolver; import org.pybee.cassowary.Variable; import java.util.HashMap; import no.agens.cassowarylayout.util.DimensionParser; import no.agens.cassowarylayout.util.TimerUtil;
} catch (ConstraintNotFound constraintNotFound) { constraintNotFound.printStackTrace(); } } public void addConstraints(CharSequence[] constraints) { for (CharSequence constraint : constraints) { try { addConstraint(constraint.toString()); } catch (RuntimeException e) { Log.e(LOG_TAG, "could not add constraint " + constraint.toString(), e); } } } public void addConstraints(int id) { String[] constraints = context.getResources().getStringArray(id); addConstraints(constraints); } public Node getContainerNode() { return containerNode; } public void solve() { long timeBeforeSolve = System.nanoTime(); solver.solve();
// Path: library/src/main/java/no/agens/cassowarylayout/util/DimensionParser.java // public class DimensionParser { // // private static Pattern pattern = Pattern.compile("^(wrapContent|matchParent)|(\\d+)(px|dp|sp|pt|in|mm)"); // // public static Double getDimension(String widthHeightString, Context context) { // // Double widthHeight = null; // // Matcher matcher = pattern.matcher(widthHeightString); // // matcher.find(); // // if (matcher.matches()) { // if (matcher.group(2) == null) { // widthHeight = (double)RelativeLayout.LayoutParams.MATCH_PARENT; // if ("wrapContent".equals(matcher.group(1))) { // widthHeight = (double)RelativeLayout.LayoutParams.WRAP_CONTENT; // } // } else { // String value = matcher.group(2); // String unit = matcher.group(3); // try { // widthHeight = (double)TypedValue.applyDimension(getUnitFromString(unit), Integer.parseInt(value), context.getResources().getDisplayMetrics()); // //widthHeight = Integer.parseInt(widthHeightString.substring(0, widthHeightString.)); // } catch (NumberFormatException e) { // // ignore // } // } // } // // return widthHeight; // // } // // private static int getUnitFromString(String unitString) { // // int unit = TypedValue.COMPLEX_UNIT_DIP; // if ("px".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_PX; // } else if ("dp".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_DIP; // } else if ("sp".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_SP; // } else if ("pt".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_PT; // } else if ("in".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_IN; // } else if ("mm".equals(unitString)) { // unit = TypedValue.COMPLEX_UNIT_MM; // } // return unit; // } // } // // Path: library/src/main/java/no/agens/cassowarylayout/util/TimerUtil.java // public class TimerUtil { // public static long since(long since) { // return (System.nanoTime() - since) / 1000000; // } // } // Path: library/src/main/java/no/agens/cassowarylayout/CassowaryModel.java import android.content.Context; import android.util.Log; import org.pybee.cassowary.Constraint; import org.pybee.cassowary.ConstraintNotFound; import org.pybee.cassowary.Expression; import org.pybee.cassowary.SimplexSolver; import org.pybee.cassowary.Variable; import java.util.HashMap; import no.agens.cassowarylayout.util.DimensionParser; import no.agens.cassowarylayout.util.TimerUtil; } catch (ConstraintNotFound constraintNotFound) { constraintNotFound.printStackTrace(); } } public void addConstraints(CharSequence[] constraints) { for (CharSequence constraint : constraints) { try { addConstraint(constraint.toString()); } catch (RuntimeException e) { Log.e(LOG_TAG, "could not add constraint " + constraint.toString(), e); } } } public void addConstraints(int id) { String[] constraints = context.getResources().getStringArray(id); addConstraints(constraints); } public Node getContainerNode() { return containerNode; } public void solve() { long timeBeforeSolve = System.nanoTime(); solver.solve();
Log.d(LOG_TAG, "solve took " + TimerUtil.since(timeBeforeSolve));
redhat-developer-demos/brewery
reporting/src/main/java/io/spring/cloud/samples/brewery/Application.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventSink.java // public interface EventSink { // // String INPUT = "events"; // // @Input(EventSink.INPUT) // SubscribableChannel input(); // }
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.sleuth.util.ExceptionUtils; import org.springframework.cloud.stream.annotation.EnableBinding; import io.spring.cloud.samples.brewery.common.events.EventSink;
package io.spring.cloud.samples.brewery; @SpringBootApplication @EnableDiscoveryClient
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventSink.java // public interface EventSink { // // String INPUT = "events"; // // @Input(EventSink.INPUT) // SubscribableChannel input(); // } // Path: reporting/src/main/java/io/spring/cloud/samples/brewery/Application.java import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.sleuth.util.ExceptionUtils; import org.springframework.cloud.stream.annotation.EnableBinding; import io.spring.cloud.samples.brewery.common.events.EventSink; package io.spring.cloud.samples.brewery; @SpringBootApplication @EnableDiscoveryClient
@EnableBinding(EventSink.class)
redhat-developer-demos/brewery
presenting/src/main/groovy/io/spring/cloud/samples/brewery/presenting/present/BrewingServiceClient.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // }
import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.presenting.config.Collaborators; import io.spring.cloud.samples.brewery.presenting.config.Versions; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod;
package io.spring.cloud.samples.brewery.presenting.present; @FeignClient(Collaborators.BREWING) @RequestMapping(value = "/ingredients", consumes = Versions.BREWING_CONTENT_TYPE_V1, produces = MediaType.APPLICATION_JSON_VALUE) public interface BrewingServiceClient { @RequestMapping(method = RequestMethod.POST) String getIngredients(String body, @RequestHeader("PROCESS-ID") String processId,
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // Path: presenting/src/main/groovy/io/spring/cloud/samples/brewery/presenting/present/BrewingServiceClient.java import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.presenting.config.Collaborators; import io.spring.cloud.samples.brewery.presenting.config.Versions; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; package io.spring.cloud.samples.brewery.presenting.present; @FeignClient(Collaborators.BREWING) @RequestMapping(value = "/ingredients", consumes = Versions.BREWING_CONTENT_TYPE_V1, produces = MediaType.APPLICATION_JSON_VALUE) public interface BrewingServiceClient { @RequestMapping(method = RequestMethod.POST) String getIngredients(String body, @RequestHeader("PROCESS-ID") String processId,
@RequestHeader(TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME) String testCommunicationType);
redhat-developer-demos/brewery
ingredients/src/main/java/io/spring/cloud/samples/brewery/ingredients/IngredientsFetchController.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // }
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.request.async.WebAsyncTask; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import lombok.extern.slf4j.Slf4j;
package io.spring.cloud.samples.brewery.ingredients; @RestController @Slf4j class IngredientsFetchController { private final StubbedIngredientsProperties stubbedIngredientsProperties; private final Tracer tracer; @Autowired IngredientsFetchController(StubbedIngredientsProperties stubbedIngredientsProperties, Tracer tracer) { this.stubbedIngredientsProperties = stubbedIngredientsProperties; this.tracer = tracer; } /** * [SLEUTH] WebAsyncTask */ @RequestMapping(value = "/{ingredient}", method = RequestMethod.POST)
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // Path: ingredients/src/main/java/io/spring/cloud/samples/brewery/ingredients/IngredientsFetchController.java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.request.async.WebAsyncTask; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import lombok.extern.slf4j.Slf4j; package io.spring.cloud.samples.brewery.ingredients; @RestController @Slf4j class IngredientsFetchController { private final StubbedIngredientsProperties stubbedIngredientsProperties; private final Tracer tracer; @Autowired IngredientsFetchController(StubbedIngredientsProperties stubbedIngredientsProperties, Tracer tracer) { this.stubbedIngredientsProperties = stubbedIngredientsProperties; this.tracer = tracer; } /** * [SLEUTH] WebAsyncTask */ @RequestMapping(value = "/{ingredient}", method = RequestMethod.POST)
public WebAsyncTask<Ingredient> ingredients(@PathVariable("ingredient") IngredientType ingredientType,
redhat-developer-demos/brewery
ingredients/src/main/java/io/spring/cloud/samples/brewery/ingredients/IngredientsFetchController.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // }
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.request.async.WebAsyncTask; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import lombok.extern.slf4j.Slf4j;
package io.spring.cloud.samples.brewery.ingredients; @RestController @Slf4j class IngredientsFetchController { private final StubbedIngredientsProperties stubbedIngredientsProperties; private final Tracer tracer; @Autowired IngredientsFetchController(StubbedIngredientsProperties stubbedIngredientsProperties, Tracer tracer) { this.stubbedIngredientsProperties = stubbedIngredientsProperties; this.tracer = tracer; } /** * [SLEUTH] WebAsyncTask */ @RequestMapping(value = "/{ingredient}", method = RequestMethod.POST)
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // Path: ingredients/src/main/java/io/spring/cloud/samples/brewery/ingredients/IngredientsFetchController.java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.request.async.WebAsyncTask; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import lombok.extern.slf4j.Slf4j; package io.spring.cloud.samples.brewery.ingredients; @RestController @Slf4j class IngredientsFetchController { private final StubbedIngredientsProperties stubbedIngredientsProperties; private final Tracer tracer; @Autowired IngredientsFetchController(StubbedIngredientsProperties stubbedIngredientsProperties, Tracer tracer) { this.stubbedIngredientsProperties = stubbedIngredientsProperties; this.tracer = tracer; } /** * [SLEUTH] WebAsyncTask */ @RequestMapping(value = "/{ingredient}", method = RequestMethod.POST)
public WebAsyncTask<Ingredient> ingredients(@PathVariable("ingredient") IngredientType ingredientType,
redhat-developer-demos/brewery
ingredients/src/main/java/io/spring/cloud/samples/brewery/ingredients/IngredientsFetchController.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // }
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.request.async.WebAsyncTask; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import lombok.extern.slf4j.Slf4j;
package io.spring.cloud.samples.brewery.ingredients; @RestController @Slf4j class IngredientsFetchController { private final StubbedIngredientsProperties stubbedIngredientsProperties; private final Tracer tracer; @Autowired IngredientsFetchController(StubbedIngredientsProperties stubbedIngredientsProperties, Tracer tracer) { this.stubbedIngredientsProperties = stubbedIngredientsProperties; this.tracer = tracer; } /** * [SLEUTH] WebAsyncTask */ @RequestMapping(value = "/{ingredient}", method = RequestMethod.POST) public WebAsyncTask<Ingredient> ingredients(@PathVariable("ingredient") IngredientType ingredientType, @RequestHeader("PROCESS-ID") String processId,
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // Path: ingredients/src/main/java/io/spring/cloud/samples/brewery/ingredients/IngredientsFetchController.java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.request.async.WebAsyncTask; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import lombok.extern.slf4j.Slf4j; package io.spring.cloud.samples.brewery.ingredients; @RestController @Slf4j class IngredientsFetchController { private final StubbedIngredientsProperties stubbedIngredientsProperties; private final Tracer tracer; @Autowired IngredientsFetchController(StubbedIngredientsProperties stubbedIngredientsProperties, Tracer tracer) { this.stubbedIngredientsProperties = stubbedIngredientsProperties; this.tracer = tracer; } /** * [SLEUTH] WebAsyncTask */ @RequestMapping(value = "/{ingredient}", method = RequestMethod.POST) public WebAsyncTask<Ingredient> ingredients(@PathVariable("ingredient") IngredientType ingredientType, @RequestHeader("PROCESS-ID") String processId,
@RequestHeader(TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME) String testCommunicationType) {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/PresentingServiceClient.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE";
import io.spring.cloud.samples.brewery.common.model.Version; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME; import static org.springframework.web.bind.annotation.RequestMethod.PUT;
package io.spring.cloud.samples.brewery.maturing; @FeignClient(Collaborators.PRESENTING) @RequestMapping("/feed") interface PresentingServiceClient { @RequestMapping( value = "/maturing",
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/PresentingServiceClient.java import io.spring.cloud.samples.brewery.common.model.Version; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME; import static org.springframework.web.bind.annotation.RequestMethod.PUT; package io.spring.cloud.samples.brewery.maturing; @FeignClient(Collaborators.PRESENTING) @RequestMapping("/feed") interface PresentingServiceClient { @RequestMapping( value = "/maturing",
produces = Version.PRESENTING_V1,
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/PresentingServiceClient.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE";
import io.spring.cloud.samples.brewery.common.model.Version; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME; import static org.springframework.web.bind.annotation.RequestMethod.PUT;
package io.spring.cloud.samples.brewery.maturing; @FeignClient(Collaborators.PRESENTING) @RequestMapping("/feed") interface PresentingServiceClient { @RequestMapping( value = "/maturing", produces = Version.PRESENTING_V1, consumes = Version.PRESENTING_V1, method = PUT) String maturingFeed(@RequestHeader("PROCESS-ID") String processId,
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/PresentingServiceClient.java import io.spring.cloud.samples.brewery.common.model.Version; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME; import static org.springframework.web.bind.annotation.RequestMethod.PUT; package io.spring.cloud.samples.brewery.maturing; @FeignClient(Collaborators.PRESENTING) @RequestMapping("/feed") interface PresentingServiceClient { @RequestMapping( value = "/maturing", produces = Version.PRESENTING_V1, consumes = Version.PRESENTING_V1, method = PUT) String maturingFeed(@RequestHeader("PROCESS-ID") String processId,
@RequestHeader(TEST_COMMUNICATION_TYPE_HEADER_NAME) String testCommunicationType);
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlingWorker.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
package io.spring.cloud.samples.brewery.bottling; @Component @Slf4j class BottlingWorker { private Map<String, State> PROCESS_STATE = new ConcurrentHashMap<>(); private final Tracer tracer; private final PresentingClient presentingClient; private final RestTemplate restTemplate;
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlingWorker.java import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; package io.spring.cloud.samples.brewery.bottling; @Component @Slf4j class BottlingWorker { private Map<String, State> PROCESS_STATE = new ConcurrentHashMap<>(); private final Tracer tracer; private final PresentingClient presentingClient; private final RestTemplate restTemplate;
private final EventGateway eventGateway;
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlingWorker.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
package io.spring.cloud.samples.brewery.bottling; @Component @Slf4j class BottlingWorker { private Map<String, State> PROCESS_STATE = new ConcurrentHashMap<>(); private final Tracer tracer; private final PresentingClient presentingClient; private final RestTemplate restTemplate; private final EventGateway eventGateway; @Autowired public BottlingWorker(Tracer tracer, PresentingClient presentingClient, @LoadBalanced RestTemplate restTemplate, EventGateway eventGateway) { this.tracer = tracer; this.presentingClient = presentingClient; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } @Async
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlingWorker.java import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; package io.spring.cloud.samples.brewery.bottling; @Component @Slf4j class BottlingWorker { private Map<String, State> PROCESS_STATE = new ConcurrentHashMap<>(); private final Tracer tracer; private final PresentingClient presentingClient; private final RestTemplate restTemplate; private final EventGateway eventGateway; @Autowired public BottlingWorker(Tracer tracer, PresentingClient presentingClient, @LoadBalanced RestTemplate restTemplate, EventGateway eventGateway) { this.tracer = tracer; this.presentingClient = presentingClient; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } @Async
public void bottleBeer(Integer wortAmount, String processId, TestConfigurationHolder configurationHolder) {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlingWorker.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
package io.spring.cloud.samples.brewery.bottling; @Component @Slf4j class BottlingWorker { private Map<String, State> PROCESS_STATE = new ConcurrentHashMap<>(); private final Tracer tracer; private final PresentingClient presentingClient; private final RestTemplate restTemplate; private final EventGateway eventGateway; @Autowired public BottlingWorker(Tracer tracer, PresentingClient presentingClient, @LoadBalanced RestTemplate restTemplate, EventGateway eventGateway) { this.tracer = tracer; this.presentingClient = presentingClient; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } @Async public void bottleBeer(Integer wortAmount, String processId, TestConfigurationHolder configurationHolder) { TestConfigurationHolder.TEST_CONFIG.set(configurationHolder); increaseBottles(wortAmount, processId);
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlingWorker.java import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; package io.spring.cloud.samples.brewery.bottling; @Component @Slf4j class BottlingWorker { private Map<String, State> PROCESS_STATE = new ConcurrentHashMap<>(); private final Tracer tracer; private final PresentingClient presentingClient; private final RestTemplate restTemplate; private final EventGateway eventGateway; @Autowired public BottlingWorker(Tracer tracer, PresentingClient presentingClient, @LoadBalanced RestTemplate restTemplate, EventGateway eventGateway) { this.tracer = tracer; this.presentingClient = presentingClient; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } @Async public void bottleBeer(Integer wortAmount, String processId, TestConfigurationHolder configurationHolder) { TestConfigurationHolder.TEST_CONFIG.set(configurationHolder); increaseBottles(wortAmount, processId);
eventGateway.emitEvent(Event.builder().eventType(EventType.BEER_BOTTLED).processId(processId).build());
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlingWorker.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
package io.spring.cloud.samples.brewery.bottling; @Component @Slf4j class BottlingWorker { private Map<String, State> PROCESS_STATE = new ConcurrentHashMap<>(); private final Tracer tracer; private final PresentingClient presentingClient; private final RestTemplate restTemplate; private final EventGateway eventGateway; @Autowired public BottlingWorker(Tracer tracer, PresentingClient presentingClient, @LoadBalanced RestTemplate restTemplate, EventGateway eventGateway) { this.tracer = tracer; this.presentingClient = presentingClient; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } @Async public void bottleBeer(Integer wortAmount, String processId, TestConfigurationHolder configurationHolder) { TestConfigurationHolder.TEST_CONFIG.set(configurationHolder); increaseBottles(wortAmount, processId);
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlingWorker.java import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; package io.spring.cloud.samples.brewery.bottling; @Component @Slf4j class BottlingWorker { private Map<String, State> PROCESS_STATE = new ConcurrentHashMap<>(); private final Tracer tracer; private final PresentingClient presentingClient; private final RestTemplate restTemplate; private final EventGateway eventGateway; @Autowired public BottlingWorker(Tracer tracer, PresentingClient presentingClient, @LoadBalanced RestTemplate restTemplate, EventGateway eventGateway) { this.tracer = tracer; this.presentingClient = presentingClient; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } @Async public void bottleBeer(Integer wortAmount, String processId, TestConfigurationHolder configurationHolder) { TestConfigurationHolder.TEST_CONFIG.set(configurationHolder); increaseBottles(wortAmount, processId);
eventGateway.emitEvent(Event.builder().eventType(EventType.BEER_BOTTLED).processId(processId).build());
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlingWorker.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
private void increaseBottles(Integer wortAmount, String processId) { log.info("Bottling beer..."); Span scope = tracer.createSpan("waiting_for_beer_bottling"); try { State stateForProcess = PROCESS_STATE.getOrDefault(processId, new State()); Integer bottled = stateForProcess.bottled; Integer bottles = stateForProcess.bottles; int bottlesCount = wortAmount / 10; bottled += bottlesCount; try { Thread.sleep(100); } catch (InterruptedException e) { // i love this construct } bottles += bottlesCount; bottled -= bottlesCount; stateForProcess.setBottled(bottled); stateForProcess.setBottles(bottles); PROCESS_STATE.put(processId, stateForProcess); } finally { tracer.close(scope); } } private void callPresentingViaFeign(String processId) { presentingClient.updateBottles(PROCESS_STATE.get(processId).getBottles(), processId, FEIGN.name()); } private void useRestTemplateToCallPresenting(String processId) {
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlingWorker.java import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; private void increaseBottles(Integer wortAmount, String processId) { log.info("Bottling beer..."); Span scope = tracer.createSpan("waiting_for_beer_bottling"); try { State stateForProcess = PROCESS_STATE.getOrDefault(processId, new State()); Integer bottled = stateForProcess.bottled; Integer bottles = stateForProcess.bottles; int bottlesCount = wortAmount / 10; bottled += bottlesCount; try { Thread.sleep(100); } catch (InterruptedException e) { // i love this construct } bottles += bottlesCount; bottled -= bottlesCount; stateForProcess.setBottled(bottled); stateForProcess.setBottles(bottles); PROCESS_STATE.put(processId, stateForProcess); } finally { tracer.close(scope); } } private void callPresentingViaFeign(String processId) { presentingClient.updateBottles(PROCESS_STATE.get(processId).getBottles(), processId, FEIGN.name()); } private void useRestTemplateToCallPresenting(String processId) {
restTemplate.exchange(requestEntity()
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlingWorker.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
log.info("Bottling beer..."); Span scope = tracer.createSpan("waiting_for_beer_bottling"); try { State stateForProcess = PROCESS_STATE.getOrDefault(processId, new State()); Integer bottled = stateForProcess.bottled; Integer bottles = stateForProcess.bottles; int bottlesCount = wortAmount / 10; bottled += bottlesCount; try { Thread.sleep(100); } catch (InterruptedException e) { // i love this construct } bottles += bottlesCount; bottled -= bottlesCount; stateForProcess.setBottled(bottled); stateForProcess.setBottles(bottles); PROCESS_STATE.put(processId, stateForProcess); } finally { tracer.close(scope); } } private void callPresentingViaFeign(String processId) { presentingClient.updateBottles(PROCESS_STATE.get(processId).getBottles(), processId, FEIGN.name()); } private void useRestTemplateToCallPresenting(String processId) { restTemplate.exchange(requestEntity() .processId(processId)
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlingWorker.java import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; log.info("Bottling beer..."); Span scope = tracer.createSpan("waiting_for_beer_bottling"); try { State stateForProcess = PROCESS_STATE.getOrDefault(processId, new State()); Integer bottled = stateForProcess.bottled; Integer bottles = stateForProcess.bottles; int bottlesCount = wortAmount / 10; bottled += bottlesCount; try { Thread.sleep(100); } catch (InterruptedException e) { // i love this construct } bottles += bottlesCount; bottled -= bottlesCount; stateForProcess.setBottled(bottled); stateForProcess.setBottles(bottles); PROCESS_STATE.put(processId, stateForProcess); } finally { tracer.close(scope); } } private void callPresentingViaFeign(String processId) { presentingClient.updateBottles(PROCESS_STATE.get(processId).getBottles(), processId, FEIGN.name()); } private void useRestTemplateToCallPresenting(String processId) { restTemplate.exchange(requestEntity() .processId(processId)
.contentTypeVersion(Version.PRESENTING_V1)
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/Bottler.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // }
import com.netflix.hystrix.HystrixCommand; import com.netflix.hystrix.HystrixCommandGroupKey; import com.netflix.hystrix.HystrixCommandKey; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.hystrix.TraceCommand; import org.springframework.stereotype.Service; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j;
package io.spring.cloud.samples.brewery.bottling; @Service @Slf4j class Bottler implements BottlingService { private final BottlerService bottlerService; private final Tracer tracer; private final TraceKeys traceKeys; @Autowired public Bottler(BottlerService bottlerService, Tracer tracer, TraceKeys traceKeys) { this.bottlerService = bottlerService; this.tracer = tracer; this.traceKeys = traceKeys; } /** * [SLEUTH] TraceCommand */ @Override
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/Bottler.java import com.netflix.hystrix.HystrixCommand; import com.netflix.hystrix.HystrixCommandGroupKey; import com.netflix.hystrix.HystrixCommandKey; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.hystrix.TraceCommand; import org.springframework.stereotype.Service; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; package io.spring.cloud.samples.brewery.bottling; @Service @Slf4j class Bottler implements BottlingService { private final BottlerService bottlerService; private final Tracer tracer; private final TraceKeys traceKeys; @Autowired public Bottler(BottlerService bottlerService, Tracer tracer, TraceKeys traceKeys) { this.bottlerService = bottlerService; this.tracer = tracer; this.traceKeys = traceKeys; } /** * [SLEUTH] TraceCommand */ @Override
public void bottle(Wort wort, String processId, String testCommunicationType) {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/Bottler.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // }
import com.netflix.hystrix.HystrixCommand; import com.netflix.hystrix.HystrixCommandGroupKey; import com.netflix.hystrix.HystrixCommandKey; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.hystrix.TraceCommand; import org.springframework.stereotype.Service; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j;
package io.spring.cloud.samples.brewery.bottling; @Service @Slf4j class Bottler implements BottlingService { private final BottlerService bottlerService; private final Tracer tracer; private final TraceKeys traceKeys; @Autowired public Bottler(BottlerService bottlerService, Tracer tracer, TraceKeys traceKeys) { this.bottlerService = bottlerService; this.tracer = tracer; this.traceKeys = traceKeys; } /** * [SLEUTH] TraceCommand */ @Override public void bottle(Wort wort, String processId, String testCommunicationType) { log.info("I'm in the bottling service"); log.info("Process ID from headers {}", processId); String groupKey = "bottling"; String commandKey = "bottle"; HystrixCommand.Setter setter = HystrixCommand.Setter .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/Bottler.java import com.netflix.hystrix.HystrixCommand; import com.netflix.hystrix.HystrixCommandGroupKey; import com.netflix.hystrix.HystrixCommandKey; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.hystrix.TraceCommand; import org.springframework.stereotype.Service; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; package io.spring.cloud.samples.brewery.bottling; @Service @Slf4j class Bottler implements BottlingService { private final BottlerService bottlerService; private final Tracer tracer; private final TraceKeys traceKeys; @Autowired public Bottler(BottlerService bottlerService, Tracer tracer, TraceKeys traceKeys) { this.bottlerService = bottlerService; this.tracer = tracer; this.traceKeys = traceKeys; } /** * [SLEUTH] TraceCommand */ @Override public void bottle(Wort wort, String processId, String testCommunicationType) { log.info("I'm in the bottling service"); log.info("Process ID from headers {}", processId); String groupKey = "bottling"; String commandKey = "bottle"; HystrixCommand.Setter setter = HystrixCommand.Setter .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
TestConfigurationHolder testConfigurationHolder = TestConfigurationHolder.TEST_CONFIG.get();
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsAggregator.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // }
import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.SpanNamer; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.async.TraceableExecutorService; import org.springframework.stereotype.Component; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import lombok.extern.slf4j.Slf4j;
package io.spring.cloud.samples.brewery.aggregating; @Slf4j @Component class IngredientsAggregator { private final MaturingServiceUpdater maturingUpdater; private final IngredientWarehouse ingredientWarehouse; private final IngredientsCollector ingredientsCollector; private final Tracer tracer;
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsAggregator.java import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.SpanNamer; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.async.TraceableExecutorService; import org.springframework.stereotype.Component; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import lombok.extern.slf4j.Slf4j; package io.spring.cloud.samples.brewery.aggregating; @Slf4j @Component class IngredientsAggregator { private final MaturingServiceUpdater maturingUpdater; private final IngredientWarehouse ingredientWarehouse; private final IngredientsCollector ingredientsCollector; private final Tracer tracer;
private final EventGateway eventGateway;
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsAggregator.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // }
import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.SpanNamer; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.async.TraceableExecutorService; import org.springframework.stereotype.Component; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import lombok.extern.slf4j.Slf4j;
package io.spring.cloud.samples.brewery.aggregating; @Slf4j @Component class IngredientsAggregator { private final MaturingServiceUpdater maturingUpdater; private final IngredientWarehouse ingredientWarehouse; private final IngredientsCollector ingredientsCollector; private final Tracer tracer; private final EventGateway eventGateway; private final TraceKeys traceKeys; private final SpanNamer spanNamer; @Autowired IngredientsAggregator(IngredientWarehouse ingredientWarehouse, MaturingServiceUpdater maturingServiceUpdater, IngredientsCollector ingredientsCollector, Tracer tracer, EventGateway eventGateway, TraceKeys traceKeys, SpanNamer spanNamer) { this.ingredientWarehouse = ingredientWarehouse; this.ingredientsCollector = ingredientsCollector; this.maturingUpdater = maturingServiceUpdater; this.tracer = tracer; this.eventGateway = eventGateway; this.traceKeys = traceKeys; this.spanNamer = spanNamer; } // TODO: Consider simplifying the case by removing the DB (always matches threshold)
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsAggregator.java import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.SpanNamer; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.async.TraceableExecutorService; import org.springframework.stereotype.Component; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import lombok.extern.slf4j.Slf4j; package io.spring.cloud.samples.brewery.aggregating; @Slf4j @Component class IngredientsAggregator { private final MaturingServiceUpdater maturingUpdater; private final IngredientWarehouse ingredientWarehouse; private final IngredientsCollector ingredientsCollector; private final Tracer tracer; private final EventGateway eventGateway; private final TraceKeys traceKeys; private final SpanNamer spanNamer; @Autowired IngredientsAggregator(IngredientWarehouse ingredientWarehouse, MaturingServiceUpdater maturingServiceUpdater, IngredientsCollector ingredientsCollector, Tracer tracer, EventGateway eventGateway, TraceKeys traceKeys, SpanNamer spanNamer) { this.ingredientWarehouse = ingredientWarehouse; this.ingredientsCollector = ingredientsCollector; this.maturingUpdater = maturingServiceUpdater; this.tracer = tracer; this.eventGateway = eventGateway; this.traceKeys = traceKeys; this.spanNamer = spanNamer; } // TODO: Consider simplifying the case by removing the DB (always matches threshold)
public Ingredients fetchIngredients(Order order, String processId, TestConfigurationHolder testConfigurationHolder) throws Exception {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsAggregator.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // }
import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.SpanNamer; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.async.TraceableExecutorService; import org.springframework.stereotype.Component; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import lombok.extern.slf4j.Slf4j;
package io.spring.cloud.samples.brewery.aggregating; @Slf4j @Component class IngredientsAggregator { private final MaturingServiceUpdater maturingUpdater; private final IngredientWarehouse ingredientWarehouse; private final IngredientsCollector ingredientsCollector; private final Tracer tracer; private final EventGateway eventGateway; private final TraceKeys traceKeys; private final SpanNamer spanNamer; @Autowired IngredientsAggregator(IngredientWarehouse ingredientWarehouse, MaturingServiceUpdater maturingServiceUpdater, IngredientsCollector ingredientsCollector, Tracer tracer, EventGateway eventGateway, TraceKeys traceKeys, SpanNamer spanNamer) { this.ingredientWarehouse = ingredientWarehouse; this.ingredientsCollector = ingredientsCollector; this.maturingUpdater = maturingServiceUpdater; this.tracer = tracer; this.eventGateway = eventGateway; this.traceKeys = traceKeys; this.spanNamer = spanNamer; } // TODO: Consider simplifying the case by removing the DB (always matches threshold)
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsAggregator.java import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.SpanNamer; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.async.TraceableExecutorService; import org.springframework.stereotype.Component; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import lombok.extern.slf4j.Slf4j; package io.spring.cloud.samples.brewery.aggregating; @Slf4j @Component class IngredientsAggregator { private final MaturingServiceUpdater maturingUpdater; private final IngredientWarehouse ingredientWarehouse; private final IngredientsCollector ingredientsCollector; private final Tracer tracer; private final EventGateway eventGateway; private final TraceKeys traceKeys; private final SpanNamer spanNamer; @Autowired IngredientsAggregator(IngredientWarehouse ingredientWarehouse, MaturingServiceUpdater maturingServiceUpdater, IngredientsCollector ingredientsCollector, Tracer tracer, EventGateway eventGateway, TraceKeys traceKeys, SpanNamer spanNamer) { this.ingredientWarehouse = ingredientWarehouse; this.ingredientsCollector = ingredientsCollector; this.maturingUpdater = maturingServiceUpdater; this.tracer = tracer; this.eventGateway = eventGateway; this.traceKeys = traceKeys; this.spanNamer = spanNamer; } // TODO: Consider simplifying the case by removing the DB (always matches threshold)
public Ingredients fetchIngredients(Order order, String processId, TestConfigurationHolder testConfigurationHolder) throws Exception {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsAggregator.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // }
import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.SpanNamer; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.async.TraceableExecutorService; import org.springframework.stereotype.Component; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import lombok.extern.slf4j.Slf4j;
package io.spring.cloud.samples.brewery.aggregating; @Slf4j @Component class IngredientsAggregator { private final MaturingServiceUpdater maturingUpdater; private final IngredientWarehouse ingredientWarehouse; private final IngredientsCollector ingredientsCollector; private final Tracer tracer; private final EventGateway eventGateway; private final TraceKeys traceKeys; private final SpanNamer spanNamer; @Autowired IngredientsAggregator(IngredientWarehouse ingredientWarehouse, MaturingServiceUpdater maturingServiceUpdater, IngredientsCollector ingredientsCollector, Tracer tracer, EventGateway eventGateway, TraceKeys traceKeys, SpanNamer spanNamer) { this.ingredientWarehouse = ingredientWarehouse; this.ingredientsCollector = ingredientsCollector; this.maturingUpdater = maturingServiceUpdater; this.tracer = tracer; this.eventGateway = eventGateway; this.traceKeys = traceKeys; this.spanNamer = spanNamer; } // TODO: Consider simplifying the case by removing the DB (always matches threshold)
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsAggregator.java import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.SpanNamer; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.async.TraceableExecutorService; import org.springframework.stereotype.Component; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import lombok.extern.slf4j.Slf4j; package io.spring.cloud.samples.brewery.aggregating; @Slf4j @Component class IngredientsAggregator { private final MaturingServiceUpdater maturingUpdater; private final IngredientWarehouse ingredientWarehouse; private final IngredientsCollector ingredientsCollector; private final Tracer tracer; private final EventGateway eventGateway; private final TraceKeys traceKeys; private final SpanNamer spanNamer; @Autowired IngredientsAggregator(IngredientWarehouse ingredientWarehouse, MaturingServiceUpdater maturingServiceUpdater, IngredientsCollector ingredientsCollector, Tracer tracer, EventGateway eventGateway, TraceKeys traceKeys, SpanNamer spanNamer) { this.ingredientWarehouse = ingredientWarehouse; this.ingredientsCollector = ingredientsCollector; this.maturingUpdater = maturingServiceUpdater; this.tracer = tracer; this.eventGateway = eventGateway; this.traceKeys = traceKeys; this.spanNamer = spanNamer; } // TODO: Consider simplifying the case by removing the DB (always matches threshold)
public Ingredients fetchIngredients(Order order, String processId, TestConfigurationHolder testConfigurationHolder) throws Exception {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsAggregator.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // }
import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.SpanNamer; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.async.TraceableExecutorService; import org.springframework.stereotype.Component; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import lombok.extern.slf4j.Slf4j;
package io.spring.cloud.samples.brewery.aggregating; @Slf4j @Component class IngredientsAggregator { private final MaturingServiceUpdater maturingUpdater; private final IngredientWarehouse ingredientWarehouse; private final IngredientsCollector ingredientsCollector; private final Tracer tracer; private final EventGateway eventGateway; private final TraceKeys traceKeys; private final SpanNamer spanNamer; @Autowired IngredientsAggregator(IngredientWarehouse ingredientWarehouse, MaturingServiceUpdater maturingServiceUpdater, IngredientsCollector ingredientsCollector, Tracer tracer, EventGateway eventGateway, TraceKeys traceKeys, SpanNamer spanNamer) { this.ingredientWarehouse = ingredientWarehouse; this.ingredientsCollector = ingredientsCollector; this.maturingUpdater = maturingServiceUpdater; this.tracer = tracer; this.eventGateway = eventGateway; this.traceKeys = traceKeys; this.spanNamer = spanNamer; } // TODO: Consider simplifying the case by removing the DB (always matches threshold) public Ingredients fetchIngredients(Order order, String processId, TestConfigurationHolder testConfigurationHolder) throws Exception { TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder); log.info("Fetching ingredients for order [{}] , processId [{}], span [{}]", order, processId); /** * [SLEUTH] ParallelStreams won't work out of the box * - example of a completable future with our TraceableExecutorService * - makes little business sense here but that's just an example */ CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> { TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder); ingredientsCollector.collectIngredients(order, processId).stream() .filter(ingredient -> ingredient != null)
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsAggregator.java import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.SpanNamer; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.async.TraceableExecutorService; import org.springframework.stereotype.Component; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import lombok.extern.slf4j.Slf4j; package io.spring.cloud.samples.brewery.aggregating; @Slf4j @Component class IngredientsAggregator { private final MaturingServiceUpdater maturingUpdater; private final IngredientWarehouse ingredientWarehouse; private final IngredientsCollector ingredientsCollector; private final Tracer tracer; private final EventGateway eventGateway; private final TraceKeys traceKeys; private final SpanNamer spanNamer; @Autowired IngredientsAggregator(IngredientWarehouse ingredientWarehouse, MaturingServiceUpdater maturingServiceUpdater, IngredientsCollector ingredientsCollector, Tracer tracer, EventGateway eventGateway, TraceKeys traceKeys, SpanNamer spanNamer) { this.ingredientWarehouse = ingredientWarehouse; this.ingredientsCollector = ingredientsCollector; this.maturingUpdater = maturingServiceUpdater; this.tracer = tracer; this.eventGateway = eventGateway; this.traceKeys = traceKeys; this.spanNamer = spanNamer; } // TODO: Consider simplifying the case by removing the DB (always matches threshold) public Ingredients fetchIngredients(Order order, String processId, TestConfigurationHolder testConfigurationHolder) throws Exception { TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder); log.info("Fetching ingredients for order [{}] , processId [{}], span [{}]", order, processId); /** * [SLEUTH] ParallelStreams won't work out of the box * - example of a completable future with our TraceableExecutorService * - makes little business sense here but that's just an example */ CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> { TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder); ingredientsCollector.collectIngredients(order, processId).stream() .filter(ingredient -> ingredient != null)
.forEach((Ingredient ingredient) -> {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsAggregator.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // }
import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.SpanNamer; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.async.TraceableExecutorService; import org.springframework.stereotype.Component; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import lombok.extern.slf4j.Slf4j;
this.ingredientsCollector = ingredientsCollector; this.maturingUpdater = maturingServiceUpdater; this.tracer = tracer; this.eventGateway = eventGateway; this.traceKeys = traceKeys; this.spanNamer = spanNamer; } // TODO: Consider simplifying the case by removing the DB (always matches threshold) public Ingredients fetchIngredients(Order order, String processId, TestConfigurationHolder testConfigurationHolder) throws Exception { TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder); log.info("Fetching ingredients for order [{}] , processId [{}], span [{}]", order, processId); /** * [SLEUTH] ParallelStreams won't work out of the box * - example of a completable future with our TraceableExecutorService * - makes little business sense here but that's just an example */ CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> { TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder); ingredientsCollector.collectIngredients(order, processId).stream() .filter(ingredient -> ingredient != null) .forEach((Ingredient ingredient) -> { log.info("Adding an ingredient [{}] for order [{}] , processId [{}]", ingredient); ingredientWarehouse.addIngredient(ingredient); }); return null; }, new TraceableExecutorService(Executors.newFixedThreadPool(5), tracer, traceKeys, spanNamer, "fetchIngredients")); // block to perform the request (as I said the example is stupid) completableFuture.get();
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsAggregator.java import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.SpanNamer; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.async.TraceableExecutorService; import org.springframework.stereotype.Component; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import lombok.extern.slf4j.Slf4j; this.ingredientsCollector = ingredientsCollector; this.maturingUpdater = maturingServiceUpdater; this.tracer = tracer; this.eventGateway = eventGateway; this.traceKeys = traceKeys; this.spanNamer = spanNamer; } // TODO: Consider simplifying the case by removing the DB (always matches threshold) public Ingredients fetchIngredients(Order order, String processId, TestConfigurationHolder testConfigurationHolder) throws Exception { TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder); log.info("Fetching ingredients for order [{}] , processId [{}], span [{}]", order, processId); /** * [SLEUTH] ParallelStreams won't work out of the box * - example of a completable future with our TraceableExecutorService * - makes little business sense here but that's just an example */ CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> { TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder); ingredientsCollector.collectIngredients(order, processId).stream() .filter(ingredient -> ingredient != null) .forEach((Ingredient ingredient) -> { log.info("Adding an ingredient [{}] for order [{}] , processId [{}]", ingredient); ingredientWarehouse.addIngredient(ingredient); }); return null; }, new TraceableExecutorService(Executors.newFixedThreadPool(5), tracer, traceKeys, spanNamer, "fetchIngredients")); // block to perform the request (as I said the example is stupid) completableFuture.get();
eventGateway.emitEvent(Event.builder().eventType(EventType.INGREDIENTS_ORDERED).processId(processId).build());
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsAggregator.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // }
import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.SpanNamer; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.async.TraceableExecutorService; import org.springframework.stereotype.Component; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import lombok.extern.slf4j.Slf4j;
this.ingredientsCollector = ingredientsCollector; this.maturingUpdater = maturingServiceUpdater; this.tracer = tracer; this.eventGateway = eventGateway; this.traceKeys = traceKeys; this.spanNamer = spanNamer; } // TODO: Consider simplifying the case by removing the DB (always matches threshold) public Ingredients fetchIngredients(Order order, String processId, TestConfigurationHolder testConfigurationHolder) throws Exception { TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder); log.info("Fetching ingredients for order [{}] , processId [{}], span [{}]", order, processId); /** * [SLEUTH] ParallelStreams won't work out of the box * - example of a completable future with our TraceableExecutorService * - makes little business sense here but that's just an example */ CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> { TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder); ingredientsCollector.collectIngredients(order, processId).stream() .filter(ingredient -> ingredient != null) .forEach((Ingredient ingredient) -> { log.info("Adding an ingredient [{}] for order [{}] , processId [{}]", ingredient); ingredientWarehouse.addIngredient(ingredient); }); return null; }, new TraceableExecutorService(Executors.newFixedThreadPool(5), tracer, traceKeys, spanNamer, "fetchIngredients")); // block to perform the request (as I said the example is stupid) completableFuture.get();
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsAggregator.java import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.SpanNamer; import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.TraceKeys; import org.springframework.cloud.sleuth.instrument.async.TraceableExecutorService; import org.springframework.stereotype.Component; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import lombok.extern.slf4j.Slf4j; this.ingredientsCollector = ingredientsCollector; this.maturingUpdater = maturingServiceUpdater; this.tracer = tracer; this.eventGateway = eventGateway; this.traceKeys = traceKeys; this.spanNamer = spanNamer; } // TODO: Consider simplifying the case by removing the DB (always matches threshold) public Ingredients fetchIngredients(Order order, String processId, TestConfigurationHolder testConfigurationHolder) throws Exception { TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder); log.info("Fetching ingredients for order [{}] , processId [{}], span [{}]", order, processId); /** * [SLEUTH] ParallelStreams won't work out of the box * - example of a completable future with our TraceableExecutorService * - makes little business sense here but that's just an example */ CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> { TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder); ingredientsCollector.collectIngredients(order, processId).stream() .filter(ingredient -> ingredient != null) .forEach((Ingredient ingredient) -> { log.info("Adding an ingredient [{}] for order [{}] , processId [{}]", ingredient); ingredientWarehouse.addIngredient(ingredient); }); return null; }, new TraceableExecutorService(Executors.newFixedThreadPool(5), tracer, traceKeys, spanNamer, "fetchIngredients")); // block to perform the request (as I said the example is stupid) completableFuture.get();
eventGateway.emitEvent(Event.builder().eventType(EventType.INGREDIENTS_ORDERED).processId(processId).build());
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsController.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // }
import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import java.util.concurrent.Callable;
package io.spring.cloud.samples.brewery.aggregating; @RestController @RequestMapping(value = "/ingredients", consumes = Version.BREWING_V1, produces = MediaType.APPLICATION_JSON_VALUE) @Slf4j class IngredientsController { private final IngredientsAggregator ingredientsAggregator; private final Tracer tracer; @Autowired public IngredientsController(IngredientsAggregator ingredientsAggregator, Tracer tracer) { this.ingredientsAggregator = ingredientsAggregator; this.tracer = tracer; } /** * [SLEUTH] Callable - separate thread pool */ @RequestMapping(method = RequestMethod.POST)
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsController.java import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import java.util.concurrent.Callable; package io.spring.cloud.samples.brewery.aggregating; @RestController @RequestMapping(value = "/ingredients", consumes = Version.BREWING_V1, produces = MediaType.APPLICATION_JSON_VALUE) @Slf4j class IngredientsController { private final IngredientsAggregator ingredientsAggregator; private final Tracer tracer; @Autowired public IngredientsController(IngredientsAggregator ingredientsAggregator, Tracer tracer) { this.ingredientsAggregator = ingredientsAggregator; this.tracer = tracer; } /** * [SLEUTH] Callable - separate thread pool */ @RequestMapping(method = RequestMethod.POST)
public Callable<Ingredients> distributeIngredients(@RequestBody Order order,
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsController.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // }
import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import java.util.concurrent.Callable;
package io.spring.cloud.samples.brewery.aggregating; @RestController @RequestMapping(value = "/ingredients", consumes = Version.BREWING_V1, produces = MediaType.APPLICATION_JSON_VALUE) @Slf4j class IngredientsController { private final IngredientsAggregator ingredientsAggregator; private final Tracer tracer; @Autowired public IngredientsController(IngredientsAggregator ingredientsAggregator, Tracer tracer) { this.ingredientsAggregator = ingredientsAggregator; this.tracer = tracer; } /** * [SLEUTH] Callable - separate thread pool */ @RequestMapping(method = RequestMethod.POST)
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsController.java import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import java.util.concurrent.Callable; package io.spring.cloud.samples.brewery.aggregating; @RestController @RequestMapping(value = "/ingredients", consumes = Version.BREWING_V1, produces = MediaType.APPLICATION_JSON_VALUE) @Slf4j class IngredientsController { private final IngredientsAggregator ingredientsAggregator; private final Tracer tracer; @Autowired public IngredientsController(IngredientsAggregator ingredientsAggregator, Tracer tracer) { this.ingredientsAggregator = ingredientsAggregator; this.tracer = tracer; } /** * [SLEUTH] Callable - separate thread pool */ @RequestMapping(method = RequestMethod.POST)
public Callable<Ingredients> distributeIngredients(@RequestBody Order order,
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsController.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // }
import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import java.util.concurrent.Callable;
package io.spring.cloud.samples.brewery.aggregating; @RestController @RequestMapping(value = "/ingredients", consumes = Version.BREWING_V1, produces = MediaType.APPLICATION_JSON_VALUE) @Slf4j class IngredientsController { private final IngredientsAggregator ingredientsAggregator; private final Tracer tracer; @Autowired public IngredientsController(IngredientsAggregator ingredientsAggregator, Tracer tracer) { this.ingredientsAggregator = ingredientsAggregator; this.tracer = tracer; } /** * [SLEUTH] Callable - separate thread pool */ @RequestMapping(method = RequestMethod.POST) public Callable<Ingredients> distributeIngredients(@RequestBody Order order, @RequestHeader("PROCESS-ID") String processId,
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsController.java import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Order; import io.spring.cloud.samples.brewery.common.model.Version; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import java.util.concurrent.Callable; package io.spring.cloud.samples.brewery.aggregating; @RestController @RequestMapping(value = "/ingredients", consumes = Version.BREWING_V1, produces = MediaType.APPLICATION_JSON_VALUE) @Slf4j class IngredientsController { private final IngredientsAggregator ingredientsAggregator; private final Tracer tracer; @Autowired public IngredientsController(IngredientsAggregator ingredientsAggregator, Tracer tracer) { this.ingredientsAggregator = ingredientsAggregator; this.tracer = tracer; } /** * [SLEUTH] Callable - separate thread pool */ @RequestMapping(method = RequestMethod.POST) public Callable<Ingredients> distributeIngredients(@RequestBody Order order, @RequestHeader("PROCESS-ID") String processId,
@RequestHeader(value = TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME,
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/AggregationConfiguration.java
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfiguration.java // @Configuration // @ComponentScan // @IntegrationComponentScan // public class TestConfiguration { // // @Bean // public FilterRegistrationBean correlationIdFilter() { // return new FilterRegistrationBean(new TestConfigurationSettingFilter()); // } // // @Bean // Sampler defaultSampler() { // return new AlwaysSampler(); // } // // @PostConstruct // public void setup() { // ExceptionUtils.setFail(true); // } // // }
import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.events.EventGateway; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.web.client.AsyncRestTemplate; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.TestConfiguration;
package io.spring.cloud.samples.brewery.aggregating; @Configuration @Import(TestConfiguration.class) class AggregationConfiguration { @Bean IngredientsProperties ingredientsProperties() { return new IngredientsProperties(); } @Bean AsyncRestTemplate asyncRestTemplate() { return new AsyncRestTemplate(); } @Bean @LoadBalanced public RestTemplate loadBalancedRestTemplate() { return new RestTemplate(); } @Bean MaturingServiceUpdater maturingServiceUpdater(IngredientsProperties ingredientsProperties, IngredientWarehouse ingredientWarehouse,
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfiguration.java // @Configuration // @ComponentScan // @IntegrationComponentScan // public class TestConfiguration { // // @Bean // public FilterRegistrationBean correlationIdFilter() { // return new FilterRegistrationBean(new TestConfigurationSettingFilter()); // } // // @Bean // Sampler defaultSampler() { // return new AlwaysSampler(); // } // // @PostConstruct // public void setup() { // ExceptionUtils.setFail(true); // } // // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/AggregationConfiguration.java import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.events.EventGateway; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.web.client.AsyncRestTemplate; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.TestConfiguration; package io.spring.cloud.samples.brewery.aggregating; @Configuration @Import(TestConfiguration.class) class AggregationConfiguration { @Bean IngredientsProperties ingredientsProperties() { return new IngredientsProperties(); } @Bean AsyncRestTemplate asyncRestTemplate() { return new AsyncRestTemplate(); } @Bean @LoadBalanced public RestTemplate loadBalancedRestTemplate() { return new RestTemplate(); } @Bean MaturingServiceUpdater maturingServiceUpdater(IngredientsProperties ingredientsProperties, IngredientWarehouse ingredientWarehouse,
MaturingService maturingService,
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/AggregationConfiguration.java
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfiguration.java // @Configuration // @ComponentScan // @IntegrationComponentScan // public class TestConfiguration { // // @Bean // public FilterRegistrationBean correlationIdFilter() { // return new FilterRegistrationBean(new TestConfigurationSettingFilter()); // } // // @Bean // Sampler defaultSampler() { // return new AlwaysSampler(); // } // // @PostConstruct // public void setup() { // ExceptionUtils.setFail(true); // } // // }
import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.events.EventGateway; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.web.client.AsyncRestTemplate; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.TestConfiguration;
package io.spring.cloud.samples.brewery.aggregating; @Configuration @Import(TestConfiguration.class) class AggregationConfiguration { @Bean IngredientsProperties ingredientsProperties() { return new IngredientsProperties(); } @Bean AsyncRestTemplate asyncRestTemplate() { return new AsyncRestTemplate(); } @Bean @LoadBalanced public RestTemplate loadBalancedRestTemplate() { return new RestTemplate(); } @Bean MaturingServiceUpdater maturingServiceUpdater(IngredientsProperties ingredientsProperties, IngredientWarehouse ingredientWarehouse, MaturingService maturingService, @LoadBalanced RestTemplate restTemplate,
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfiguration.java // @Configuration // @ComponentScan // @IntegrationComponentScan // public class TestConfiguration { // // @Bean // public FilterRegistrationBean correlationIdFilter() { // return new FilterRegistrationBean(new TestConfigurationSettingFilter()); // } // // @Bean // Sampler defaultSampler() { // return new AlwaysSampler(); // } // // @PostConstruct // public void setup() { // ExceptionUtils.setFail(true); // } // // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/AggregationConfiguration.java import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.events.EventGateway; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.web.client.AsyncRestTemplate; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.TestConfiguration; package io.spring.cloud.samples.brewery.aggregating; @Configuration @Import(TestConfiguration.class) class AggregationConfiguration { @Bean IngredientsProperties ingredientsProperties() { return new IngredientsProperties(); } @Bean AsyncRestTemplate asyncRestTemplate() { return new AsyncRestTemplate(); } @Bean @LoadBalanced public RestTemplate loadBalancedRestTemplate() { return new RestTemplate(); } @Bean MaturingServiceUpdater maturingServiceUpdater(IngredientsProperties ingredientsProperties, IngredientWarehouse ingredientWarehouse, MaturingService maturingService, @LoadBalanced RestTemplate restTemplate,
EventGateway eventGateway) {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsCollector.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Order; import org.slf4j.Logger; import org.springframework.http.HttpMethod; import org.springframework.web.client.RestTemplate; import java.lang.invoke.MethodHandles; import java.util.List; import java.util.concurrent.Callable; import java.util.stream.Collectors; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; import static org.slf4j.LoggerFactory.getLogger;
package io.spring.cloud.samples.brewery.aggregating; class IngredientsCollector { private static final Logger log = getLogger(MethodHandles.lookup().lookupClass()); private final RestTemplate restTemplate; private final IngredientsProxy ingredientsProxy; public IngredientsCollector(RestTemplate restTemplate, IngredientsProxy ingredientsProxy) { this.restTemplate = restTemplate; this.ingredientsProxy = ingredientsProxy; }
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsCollector.java import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Order; import org.slf4j.Logger; import org.springframework.http.HttpMethod; import org.springframework.web.client.RestTemplate; import java.lang.invoke.MethodHandles; import java.util.List; import java.util.concurrent.Callable; import java.util.stream.Collectors; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; import static org.slf4j.LoggerFactory.getLogger; package io.spring.cloud.samples.brewery.aggregating; class IngredientsCollector { private static final Logger log = getLogger(MethodHandles.lookup().lookupClass()); private final RestTemplate restTemplate; private final IngredientsProxy ingredientsProxy; public IngredientsCollector(RestTemplate restTemplate, IngredientsProxy ingredientsProxy) { this.restTemplate = restTemplate; this.ingredientsProxy = ingredientsProxy; }
List<Ingredient> collectIngredients(Order order, String processId) {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsCollector.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Order; import org.slf4j.Logger; import org.springframework.http.HttpMethod; import org.springframework.web.client.RestTemplate; import java.lang.invoke.MethodHandles; import java.util.List; import java.util.concurrent.Callable; import java.util.stream.Collectors; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; import static org.slf4j.LoggerFactory.getLogger;
package io.spring.cloud.samples.brewery.aggregating; class IngredientsCollector { private static final Logger log = getLogger(MethodHandles.lookup().lookupClass()); private final RestTemplate restTemplate; private final IngredientsProxy ingredientsProxy; public IngredientsCollector(RestTemplate restTemplate, IngredientsProxy ingredientsProxy) { this.restTemplate = restTemplate; this.ingredientsProxy = ingredientsProxy; }
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsCollector.java import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Order; import org.slf4j.Logger; import org.springframework.http.HttpMethod; import org.springframework.web.client.RestTemplate; import java.lang.invoke.MethodHandles; import java.util.List; import java.util.concurrent.Callable; import java.util.stream.Collectors; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; import static org.slf4j.LoggerFactory.getLogger; package io.spring.cloud.samples.brewery.aggregating; class IngredientsCollector { private static final Logger log = getLogger(MethodHandles.lookup().lookupClass()); private final RestTemplate restTemplate; private final IngredientsProxy ingredientsProxy; public IngredientsCollector(RestTemplate restTemplate, IngredientsProxy ingredientsProxy) { this.restTemplate = restTemplate; this.ingredientsProxy = ingredientsProxy; }
List<Ingredient> collectIngredients(Order order, String processId) {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsCollector.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Order; import org.slf4j.Logger; import org.springframework.http.HttpMethod; import org.springframework.web.client.RestTemplate; import java.lang.invoke.MethodHandles; import java.util.List; import java.util.concurrent.Callable; import java.util.stream.Collectors; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; import static org.slf4j.LoggerFactory.getLogger;
package io.spring.cloud.samples.brewery.aggregating; class IngredientsCollector { private static final Logger log = getLogger(MethodHandles.lookup().lookupClass()); private final RestTemplate restTemplate; private final IngredientsProxy ingredientsProxy; public IngredientsCollector(RestTemplate restTemplate, IngredientsProxy ingredientsProxy) { this.restTemplate = restTemplate; this.ingredientsProxy = ingredientsProxy; } List<Ingredient> collectIngredients(Order order, String processId) {
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsCollector.java import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Order; import org.slf4j.Logger; import org.springframework.http.HttpMethod; import org.springframework.web.client.RestTemplate; import java.lang.invoke.MethodHandles; import java.util.List; import java.util.concurrent.Callable; import java.util.stream.Collectors; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; import static org.slf4j.LoggerFactory.getLogger; package io.spring.cloud.samples.brewery.aggregating; class IngredientsCollector { private static final Logger log = getLogger(MethodHandles.lookup().lookupClass()); private final RestTemplate restTemplate; private final IngredientsProxy ingredientsProxy; public IngredientsCollector(RestTemplate restTemplate, IngredientsProxy ingredientsProxy) { this.restTemplate = restTemplate; this.ingredientsProxy = ingredientsProxy; } List<Ingredient> collectIngredients(Order order, String processId) {
switch (TestConfigurationHolder.TEST_CONFIG.get().getTestCommunicationType()) {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsCollector.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Order; import org.slf4j.Logger; import org.springframework.http.HttpMethod; import org.springframework.web.client.RestTemplate; import java.lang.invoke.MethodHandles; import java.util.List; import java.util.concurrent.Callable; import java.util.stream.Collectors; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; import static org.slf4j.LoggerFactory.getLogger;
} List<Ingredient> collectIngredients(Order order, String processId) { switch (TestConfigurationHolder.TEST_CONFIG.get().getTestCommunicationType()) { case FEIGN: return callViaFeign(order, processId); default: return callViaRestTemplate(order, processId); } } private List<Ingredient> callViaFeign(Order order, String processId) { callZuulAtNonExistentUrl( () -> ingredientsProxy.nonExistentIngredients(processId, FEIGN.name())); return order.getItems() .stream() .map(item -> ingredientsProxy.ingredients(item, processId, FEIGN.name())) .collect(Collectors.toList()); } private List<Ingredient> callViaRestTemplate(Order order, String processId) { callZuulAtNonExistentUrl( () -> callZuul(processId, "api/someNonExistentUrl")); return order.getItems() .stream() .map(item -> callZuul(processId, item.name()) ) .collect(Collectors.toList()); } private Ingredient callZuul(String processId, String name) {
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Order.java // @Data // public class Order { // private List<IngredientType> items = new ArrayList<>(); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsCollector.java import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.Order; import org.slf4j.Logger; import org.springframework.http.HttpMethod; import org.springframework.web.client.RestTemplate; import java.lang.invoke.MethodHandles; import java.util.List; import java.util.concurrent.Callable; import java.util.stream.Collectors; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; import static org.slf4j.LoggerFactory.getLogger; } List<Ingredient> collectIngredients(Order order, String processId) { switch (TestConfigurationHolder.TEST_CONFIG.get().getTestCommunicationType()) { case FEIGN: return callViaFeign(order, processId); default: return callViaRestTemplate(order, processId); } } private List<Ingredient> callViaFeign(Order order, String processId) { callZuulAtNonExistentUrl( () -> ingredientsProxy.nonExistentIngredients(processId, FEIGN.name())); return order.getItems() .stream() .map(item -> ingredientsProxy.ingredients(item, processId, FEIGN.name())) .collect(Collectors.toList()); } private List<Ingredient> callViaRestTemplate(Order order, String processId) { callZuulAtNonExistentUrl( () -> callZuul(processId, "api/someNonExistentUrl")); return order.getItems() .stream() .map(item -> callZuul(processId, item.name()) ) .collect(Collectors.toList()); } private Ingredient callZuul(String processId, String name) {
return restTemplate.exchange(requestEntity()
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientWarehouse.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // }
import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import org.springframework.stereotype.Service; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors;
package io.spring.cloud.samples.brewery.aggregating; @Service class IngredientWarehouse {
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientWarehouse.java import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import org.springframework.stereotype.Service; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; package io.spring.cloud.samples.brewery.aggregating; @Service class IngredientWarehouse {
private static final Map<IngredientType, Integer> DATABASE = new ConcurrentHashMap<>();
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientWarehouse.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // }
import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import org.springframework.stereotype.Service; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors;
package io.spring.cloud.samples.brewery.aggregating; @Service class IngredientWarehouse { private static final Map<IngredientType, Integer> DATABASE = new ConcurrentHashMap<>();
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientWarehouse.java import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import org.springframework.stereotype.Service; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; package io.spring.cloud.samples.brewery.aggregating; @Service class IngredientWarehouse { private static final Map<IngredientType, Integer> DATABASE = new ConcurrentHashMap<>();
public void addIngredient(Ingredient ingredient) {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientWarehouse.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // }
import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import org.springframework.stereotype.Service; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors;
package io.spring.cloud.samples.brewery.aggregating; @Service class IngredientWarehouse { private static final Map<IngredientType, Integer> DATABASE = new ConcurrentHashMap<>(); public void addIngredient(Ingredient ingredient) { int currentQuantity = DATABASE.getOrDefault(ingredient.getType(), 0); DATABASE.put(ingredient.getType(), currentQuantity + ingredient.getQuantity()); } public void useIngredients(Integer amount) { DATABASE.forEach((ingredientType, integer) -> DATABASE.put(ingredientType, integer - amount)); }
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientWarehouse.java import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import org.springframework.stereotype.Service; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; package io.spring.cloud.samples.brewery.aggregating; @Service class IngredientWarehouse { private static final Map<IngredientType, Integer> DATABASE = new ConcurrentHashMap<>(); public void addIngredient(Ingredient ingredient) { int currentQuantity = DATABASE.getOrDefault(ingredient.getType(), 0); DATABASE.put(ingredient.getType(), currentQuantity + ingredient.getQuantity()); } public void useIngredients(Integer amount) { DATABASE.forEach((ingredientType, integer) -> DATABASE.put(ingredientType, integer - amount)); }
public Ingredients getCurrentState() {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/Application.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventSource.java // public interface EventSource { // // String OUTPUT = "events"; // // @Output(EventSource.OUTPUT) MessageChannel output(); // // }
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; import org.springframework.cloud.sleuth.util.ExceptionUtils; import org.springframework.cloud.stream.annotation.EnableBinding; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.scheduling.annotation.EnableAsync; import io.spring.cloud.samples.brewery.common.events.EventSource;
package io.spring.cloud.samples.brewery; @SpringBootApplication @EnableAsync @EnableAspectJAutoProxy(proxyTargetClass = true) @EnableDiscoveryClient @EnableFeignClients
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventSource.java // public interface EventSource { // // String OUTPUT = "events"; // // @Output(EventSource.OUTPUT) MessageChannel output(); // // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/Application.java import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; import org.springframework.cloud.sleuth.util.ExceptionUtils; import org.springframework.cloud.stream.annotation.EnableBinding; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.scheduling.annotation.EnableAsync; import io.spring.cloud.samples.brewery.common.events.EventSource; package io.spring.cloud.samples.brewery; @SpringBootApplication @EnableAsync @EnableAspectJAutoProxy(proxyTargetClass = true) @EnableDiscoveryClient @EnableFeignClients
@EnableBinding(EventSource.class)
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BottlingServiceUpdater.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
package io.spring.cloud.samples.brewery.maturing; @Slf4j class BottlingServiceUpdater { private final BrewProperties brewProperties; private final Tracer tracer; private final PresentingServiceClient presentingServiceClient; private final BottlingService bottlingService; private final RestTemplate restTemplate;
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BottlingServiceUpdater.java import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; package io.spring.cloud.samples.brewery.maturing; @Slf4j class BottlingServiceUpdater { private final BrewProperties brewProperties; private final Tracer tracer; private final PresentingServiceClient presentingServiceClient; private final BottlingService bottlingService; private final RestTemplate restTemplate;
private final EventGateway eventGateway;
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BottlingServiceUpdater.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
package io.spring.cloud.samples.brewery.maturing; @Slf4j class BottlingServiceUpdater { private final BrewProperties brewProperties; private final Tracer tracer; private final PresentingServiceClient presentingServiceClient; private final BottlingService bottlingService; private final RestTemplate restTemplate; private final EventGateway eventGateway; public BottlingServiceUpdater(BrewProperties brewProperties, Tracer tracer, PresentingServiceClient presentingServiceClient, BottlingService bottlingService, RestTemplate restTemplate, EventGateway eventGateway) { this.brewProperties = brewProperties; this.tracer = tracer; this.presentingServiceClient = presentingServiceClient; this.bottlingService = bottlingService; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } @Async
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BottlingServiceUpdater.java import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; package io.spring.cloud.samples.brewery.maturing; @Slf4j class BottlingServiceUpdater { private final BrewProperties brewProperties; private final Tracer tracer; private final PresentingServiceClient presentingServiceClient; private final BottlingService bottlingService; private final RestTemplate restTemplate; private final EventGateway eventGateway; public BottlingServiceUpdater(BrewProperties brewProperties, Tracer tracer, PresentingServiceClient presentingServiceClient, BottlingService bottlingService, RestTemplate restTemplate, EventGateway eventGateway) { this.brewProperties = brewProperties; this.tracer = tracer; this.presentingServiceClient = presentingServiceClient; this.bottlingService = bottlingService; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } @Async
public void updateBottlingServiceAboutBrewedBeer(final Ingredients ingredients, String processId, TestConfigurationHolder configurationHolder) {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BottlingServiceUpdater.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
package io.spring.cloud.samples.brewery.maturing; @Slf4j class BottlingServiceUpdater { private final BrewProperties brewProperties; private final Tracer tracer; private final PresentingServiceClient presentingServiceClient; private final BottlingService bottlingService; private final RestTemplate restTemplate; private final EventGateway eventGateway; public BottlingServiceUpdater(BrewProperties brewProperties, Tracer tracer, PresentingServiceClient presentingServiceClient, BottlingService bottlingService, RestTemplate restTemplate, EventGateway eventGateway) { this.brewProperties = brewProperties; this.tracer = tracer; this.presentingServiceClient = presentingServiceClient; this.bottlingService = bottlingService; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } @Async
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BottlingServiceUpdater.java import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; package io.spring.cloud.samples.brewery.maturing; @Slf4j class BottlingServiceUpdater { private final BrewProperties brewProperties; private final Tracer tracer; private final PresentingServiceClient presentingServiceClient; private final BottlingService bottlingService; private final RestTemplate restTemplate; private final EventGateway eventGateway; public BottlingServiceUpdater(BrewProperties brewProperties, Tracer tracer, PresentingServiceClient presentingServiceClient, BottlingService bottlingService, RestTemplate restTemplate, EventGateway eventGateway) { this.brewProperties = brewProperties; this.tracer = tracer; this.presentingServiceClient = presentingServiceClient; this.bottlingService = bottlingService; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } @Async
public void updateBottlingServiceAboutBrewedBeer(final Ingredients ingredients, String processId, TestConfigurationHolder configurationHolder) {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BottlingServiceUpdater.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
package io.spring.cloud.samples.brewery.maturing; @Slf4j class BottlingServiceUpdater { private final BrewProperties brewProperties; private final Tracer tracer; private final PresentingServiceClient presentingServiceClient; private final BottlingService bottlingService; private final RestTemplate restTemplate; private final EventGateway eventGateway; public BottlingServiceUpdater(BrewProperties brewProperties, Tracer tracer, PresentingServiceClient presentingServiceClient, BottlingService bottlingService, RestTemplate restTemplate, EventGateway eventGateway) { this.brewProperties = brewProperties; this.tracer = tracer; this.presentingServiceClient = presentingServiceClient; this.bottlingService = bottlingService; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } @Async public void updateBottlingServiceAboutBrewedBeer(final Ingredients ingredients, String processId, TestConfigurationHolder configurationHolder) { Span trace = tracer.createSpan("inside_maturing"); try { TestConfigurationHolder.TEST_CONFIG.set(configurationHolder); log.info("Updating bottling service. Current process id is equal [{}]", processId); notifyPresentingService(processId); brewBeer();
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BottlingServiceUpdater.java import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; package io.spring.cloud.samples.brewery.maturing; @Slf4j class BottlingServiceUpdater { private final BrewProperties brewProperties; private final Tracer tracer; private final PresentingServiceClient presentingServiceClient; private final BottlingService bottlingService; private final RestTemplate restTemplate; private final EventGateway eventGateway; public BottlingServiceUpdater(BrewProperties brewProperties, Tracer tracer, PresentingServiceClient presentingServiceClient, BottlingService bottlingService, RestTemplate restTemplate, EventGateway eventGateway) { this.brewProperties = brewProperties; this.tracer = tracer; this.presentingServiceClient = presentingServiceClient; this.bottlingService = bottlingService; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } @Async public void updateBottlingServiceAboutBrewedBeer(final Ingredients ingredients, String processId, TestConfigurationHolder configurationHolder) { Span trace = tracer.createSpan("inside_maturing"); try { TestConfigurationHolder.TEST_CONFIG.set(configurationHolder); log.info("Updating bottling service. Current process id is equal [{}]", processId); notifyPresentingService(processId); brewBeer();
eventGateway.emitEvent(Event.builder().eventType(EventType.BEER_MATURED).processId(processId).build());
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BottlingServiceUpdater.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
package io.spring.cloud.samples.brewery.maturing; @Slf4j class BottlingServiceUpdater { private final BrewProperties brewProperties; private final Tracer tracer; private final PresentingServiceClient presentingServiceClient; private final BottlingService bottlingService; private final RestTemplate restTemplate; private final EventGateway eventGateway; public BottlingServiceUpdater(BrewProperties brewProperties, Tracer tracer, PresentingServiceClient presentingServiceClient, BottlingService bottlingService, RestTemplate restTemplate, EventGateway eventGateway) { this.brewProperties = brewProperties; this.tracer = tracer; this.presentingServiceClient = presentingServiceClient; this.bottlingService = bottlingService; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } @Async public void updateBottlingServiceAboutBrewedBeer(final Ingredients ingredients, String processId, TestConfigurationHolder configurationHolder) { Span trace = tracer.createSpan("inside_maturing"); try { TestConfigurationHolder.TEST_CONFIG.set(configurationHolder); log.info("Updating bottling service. Current process id is equal [{}]", processId); notifyPresentingService(processId); brewBeer();
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BottlingServiceUpdater.java import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; package io.spring.cloud.samples.brewery.maturing; @Slf4j class BottlingServiceUpdater { private final BrewProperties brewProperties; private final Tracer tracer; private final PresentingServiceClient presentingServiceClient; private final BottlingService bottlingService; private final RestTemplate restTemplate; private final EventGateway eventGateway; public BottlingServiceUpdater(BrewProperties brewProperties, Tracer tracer, PresentingServiceClient presentingServiceClient, BottlingService bottlingService, RestTemplate restTemplate, EventGateway eventGateway) { this.brewProperties = brewProperties; this.tracer = tracer; this.presentingServiceClient = presentingServiceClient; this.bottlingService = bottlingService; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } @Async public void updateBottlingServiceAboutBrewedBeer(final Ingredients ingredients, String processId, TestConfigurationHolder configurationHolder) { Span trace = tracer.createSpan("inside_maturing"); try { TestConfigurationHolder.TEST_CONFIG.set(configurationHolder); log.info("Updating bottling service. Current process id is equal [{}]", processId); notifyPresentingService(processId); brewBeer();
eventGateway.emitEvent(Event.builder().eventType(EventType.BEER_MATURED).processId(processId).build());
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BottlingServiceUpdater.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
Thread.sleep(timeout); } catch (InterruptedException e) { log.error("Exception occurred while brewing beer", e); } } private void notifyPresentingService(String correlationId) { log.info("Calling presenting from maturing"); Span scope = this.tracer.createSpan("calling_presenting_from_maturing"); switch (TestConfigurationHolder.TEST_CONFIG.get().getTestCommunicationType()) { case FEIGN: callPresentingViaFeign(correlationId); break; default: useRestTemplateToCallPresenting(correlationId); } tracer.close(scope); } private void callPresentingViaFeign(String correlationId) { presentingServiceClient.maturingFeed(correlationId, FEIGN.name()); } /** * [SLEUTH] HystrixCommand - Javanica integration */ @HystrixCommand public void notifyBottlingService(Ingredients ingredients, String correlationId) { log.info("Calling bottling from maturing"); Span scope = this.tracer.createSpan("calling_bottling_from_maturing");
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BottlingServiceUpdater.java import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; Thread.sleep(timeout); } catch (InterruptedException e) { log.error("Exception occurred while brewing beer", e); } } private void notifyPresentingService(String correlationId) { log.info("Calling presenting from maturing"); Span scope = this.tracer.createSpan("calling_presenting_from_maturing"); switch (TestConfigurationHolder.TEST_CONFIG.get().getTestCommunicationType()) { case FEIGN: callPresentingViaFeign(correlationId); break; default: useRestTemplateToCallPresenting(correlationId); } tracer.close(scope); } private void callPresentingViaFeign(String correlationId) { presentingServiceClient.maturingFeed(correlationId, FEIGN.name()); } /** * [SLEUTH] HystrixCommand - Javanica integration */ @HystrixCommand public void notifyBottlingService(Ingredients ingredients, String correlationId) { log.info("Calling bottling from maturing"); Span scope = this.tracer.createSpan("calling_bottling_from_maturing");
bottlingService.bottle(new Wort(getQuantity(ingredients)), correlationId, FEIGN.name());
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BottlingServiceUpdater.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
private void notifyPresentingService(String correlationId) { log.info("Calling presenting from maturing"); Span scope = this.tracer.createSpan("calling_presenting_from_maturing"); switch (TestConfigurationHolder.TEST_CONFIG.get().getTestCommunicationType()) { case FEIGN: callPresentingViaFeign(correlationId); break; default: useRestTemplateToCallPresenting(correlationId); } tracer.close(scope); } private void callPresentingViaFeign(String correlationId) { presentingServiceClient.maturingFeed(correlationId, FEIGN.name()); } /** * [SLEUTH] HystrixCommand - Javanica integration */ @HystrixCommand public void notifyBottlingService(Ingredients ingredients, String correlationId) { log.info("Calling bottling from maturing"); Span scope = this.tracer.createSpan("calling_bottling_from_maturing"); bottlingService.bottle(new Wort(getQuantity(ingredients)), correlationId, FEIGN.name()); tracer.close(scope); } private void useRestTemplateToCallPresenting(String processId) { log.info("Calling presenting - process id [{}]", processId);
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BottlingServiceUpdater.java import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; private void notifyPresentingService(String correlationId) { log.info("Calling presenting from maturing"); Span scope = this.tracer.createSpan("calling_presenting_from_maturing"); switch (TestConfigurationHolder.TEST_CONFIG.get().getTestCommunicationType()) { case FEIGN: callPresentingViaFeign(correlationId); break; default: useRestTemplateToCallPresenting(correlationId); } tracer.close(scope); } private void callPresentingViaFeign(String correlationId) { presentingServiceClient.maturingFeed(correlationId, FEIGN.name()); } /** * [SLEUTH] HystrixCommand - Javanica integration */ @HystrixCommand public void notifyBottlingService(Ingredients ingredients, String correlationId) { log.info("Calling bottling from maturing"); Span scope = this.tracer.createSpan("calling_bottling_from_maturing"); bottlingService.bottle(new Wort(getQuantity(ingredients)), correlationId, FEIGN.name()); tracer.close(scope); } private void useRestTemplateToCallPresenting(String processId) { log.info("Calling presenting - process id [{}]", processId);
restTemplate.exchange(requestEntity()
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BottlingServiceUpdater.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
Span scope = this.tracer.createSpan("calling_presenting_from_maturing"); switch (TestConfigurationHolder.TEST_CONFIG.get().getTestCommunicationType()) { case FEIGN: callPresentingViaFeign(correlationId); break; default: useRestTemplateToCallPresenting(correlationId); } tracer.close(scope); } private void callPresentingViaFeign(String correlationId) { presentingServiceClient.maturingFeed(correlationId, FEIGN.name()); } /** * [SLEUTH] HystrixCommand - Javanica integration */ @HystrixCommand public void notifyBottlingService(Ingredients ingredients, String correlationId) { log.info("Calling bottling from maturing"); Span scope = this.tracer.createSpan("calling_bottling_from_maturing"); bottlingService.bottle(new Wort(getQuantity(ingredients)), correlationId, FEIGN.name()); tracer.close(scope); } private void useRestTemplateToCallPresenting(String processId) { log.info("Calling presenting - process id [{}]", processId); restTemplate.exchange(requestEntity() .processId(processId)
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BottlingServiceUpdater.java import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; Span scope = this.tracer.createSpan("calling_presenting_from_maturing"); switch (TestConfigurationHolder.TEST_CONFIG.get().getTestCommunicationType()) { case FEIGN: callPresentingViaFeign(correlationId); break; default: useRestTemplateToCallPresenting(correlationId); } tracer.close(scope); } private void callPresentingViaFeign(String correlationId) { presentingServiceClient.maturingFeed(correlationId, FEIGN.name()); } /** * [SLEUTH] HystrixCommand - Javanica integration */ @HystrixCommand public void notifyBottlingService(Ingredients ingredients, String correlationId) { log.info("Calling bottling from maturing"); Span scope = this.tracer.createSpan("calling_bottling_from_maturing"); bottlingService.bottle(new Wort(getQuantity(ingredients)), correlationId, FEIGN.name()); tracer.close(scope); } private void useRestTemplateToCallPresenting(String processId) { log.info("Calling presenting - process id [{}]", processId); restTemplate.exchange(requestEntity() .processId(processId)
.contentTypeVersion(Version.PRESENTING_V1)
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/Maturer.java
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // }
import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;
package io.spring.cloud.samples.brewery.maturing; @Service @Slf4j
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/Maturer.java import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; package io.spring.cloud.samples.brewery.maturing; @Service @Slf4j
class Maturer implements MaturingService {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/Maturer.java
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // }
import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;
package io.spring.cloud.samples.brewery.maturing; @Service @Slf4j class Maturer implements MaturingService { private final BottlingServiceUpdater bottlingServiceUpdater; @Autowired public Maturer(BottlingServiceUpdater bottlingServiceUpdater) { this.bottlingServiceUpdater = bottlingServiceUpdater; } @Override public void distributeIngredients(io.spring.cloud.samples.brewery.common.model.Ingredients ingredients, String processId, String testCommunicationType) { log.info("I'm in the maturing service. Will distribute ingredients");
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // @Data // @Builder // public class TestConfigurationHolder { // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // private TestCommunicationType testCommunicationType; // // public enum TestCommunicationType { // FEIGN, REST_TEMPLATE // } // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/Maturer.java import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.TestConfigurationHolder; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; package io.spring.cloud.samples.brewery.maturing; @Service @Slf4j class Maturer implements MaturingService { private final BottlingServiceUpdater bottlingServiceUpdater; @Autowired public Maturer(BottlingServiceUpdater bottlingServiceUpdater) { this.bottlingServiceUpdater = bottlingServiceUpdater; } @Override public void distributeIngredients(io.spring.cloud.samples.brewery.common.model.Ingredients ingredients, String processId, String testCommunicationType) { log.info("I'm in the maturing service. Will distribute ingredients");
TestConfigurationHolder configurationHolder = TestConfigurationHolder.builder().testCommunicationType(TestConfigurationHolder.TestCommunicationType.valueOf(testCommunicationType)).build();
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BrewConfiguration.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfiguration.java // @Configuration // @ComponentScan // @IntegrationComponentScan // public class TestConfiguration { // // @Bean // public FilterRegistrationBean correlationIdFilter() { // return new FilterRegistrationBean(new TestConfigurationSettingFilter()); // } // // @Bean // Sampler defaultSampler() { // return new AlwaysSampler(); // } // // @PostConstruct // public void setup() { // ExceptionUtils.setFail(true); // } // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // }
import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfiguration; import io.spring.cloud.samples.brewery.common.events.EventGateway; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.sleuth.Tracer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.web.client.RestTemplate;
package io.spring.cloud.samples.brewery.maturing; @Configuration @Import(TestConfiguration.class) class BrewConfiguration { @Bean @LoadBalanced public RestTemplate loadBalancedRestTemplate() { return new RestTemplate(); } @Bean BottlingServiceUpdater bottlingServiceUpdater(Tracer trace, PresentingServiceClient presentingServiceClient, BottlingService bottlingService, @LoadBalanced RestTemplate restTemplate,
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfiguration.java // @Configuration // @ComponentScan // @IntegrationComponentScan // public class TestConfiguration { // // @Bean // public FilterRegistrationBean correlationIdFilter() { // return new FilterRegistrationBean(new TestConfigurationSettingFilter()); // } // // @Bean // Sampler defaultSampler() { // return new AlwaysSampler(); // } // // @PostConstruct // public void setup() { // ExceptionUtils.setFail(true); // } // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/maturing/BrewConfiguration.java import io.spring.cloud.samples.brewery.common.BottlingService; import io.spring.cloud.samples.brewery.common.TestConfiguration; import io.spring.cloud.samples.brewery.common.events.EventGateway; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.sleuth.Tracer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.web.client.RestTemplate; package io.spring.cloud.samples.brewery.maturing; @Configuration @Import(TestConfiguration.class) class BrewConfiguration { @Bean @LoadBalanced public RestTemplate loadBalancedRestTemplate() { return new RestTemplate(); } @Bean BottlingServiceUpdater bottlingServiceUpdater(Tracer trace, PresentingServiceClient presentingServiceClient, BottlingService bottlingService, @LoadBalanced RestTemplate restTemplate,
EventGateway eventGateway) {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlerService.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.http.RequestEntity; import org.springframework.web.client.AsyncRestTemplate; import org.springframework.web.client.RestTemplate; import java.net.URI; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_CONFIG; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
package io.spring.cloud.samples.brewery.bottling; @Slf4j class BottlerService { private final BottlingWorker bottlingWorker; private final PresentingClient presentingClient; private final RestTemplate restTemplate; private final AsyncRestTemplate asyncRestTemplate; private final Tracer tracer; public BottlerService(BottlingWorker bottlingWorker, PresentingClient presentingClient, RestTemplate restTemplate, AsyncRestTemplate asyncRestTemplate, Tracer tracer) { this.bottlingWorker = bottlingWorker; this.presentingClient = presentingClient; this.restTemplate = restTemplate; this.asyncRestTemplate = asyncRestTemplate; this.tracer = tracer; } /** * [SLEUTH] HystrixCommand - Javanica integration */ @HystrixCommand
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlerService.java import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.http.RequestEntity; import org.springframework.web.client.AsyncRestTemplate; import org.springframework.web.client.RestTemplate; import java.net.URI; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_CONFIG; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; package io.spring.cloud.samples.brewery.bottling; @Slf4j class BottlerService { private final BottlingWorker bottlingWorker; private final PresentingClient presentingClient; private final RestTemplate restTemplate; private final AsyncRestTemplate asyncRestTemplate; private final Tracer tracer; public BottlerService(BottlingWorker bottlingWorker, PresentingClient presentingClient, RestTemplate restTemplate, AsyncRestTemplate asyncRestTemplate, Tracer tracer) { this.bottlingWorker = bottlingWorker; this.presentingClient = presentingClient; this.restTemplate = restTemplate; this.asyncRestTemplate = asyncRestTemplate; this.tracer = tracer; } /** * [SLEUTH] HystrixCommand - Javanica integration */ @HystrixCommand
void bottle(Wort wort, String processId) {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlerService.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.http.RequestEntity; import org.springframework.web.client.AsyncRestTemplate; import org.springframework.web.client.RestTemplate; import java.net.URI; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_CONFIG; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
package io.spring.cloud.samples.brewery.bottling; @Slf4j class BottlerService { private final BottlingWorker bottlingWorker; private final PresentingClient presentingClient; private final RestTemplate restTemplate; private final AsyncRestTemplate asyncRestTemplate; private final Tracer tracer; public BottlerService(BottlingWorker bottlingWorker, PresentingClient presentingClient, RestTemplate restTemplate, AsyncRestTemplate asyncRestTemplate, Tracer tracer) { this.bottlingWorker = bottlingWorker; this.presentingClient = presentingClient; this.restTemplate = restTemplate; this.asyncRestTemplate = asyncRestTemplate; this.tracer = tracer; } /** * [SLEUTH] HystrixCommand - Javanica integration */ @HystrixCommand void bottle(Wort wort, String processId) { log.info("I'm inside bottling"); Span span = tracer.createSpan("inside_bottling"); try { notifyPresenting(processId);
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlerService.java import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.http.RequestEntity; import org.springframework.web.client.AsyncRestTemplate; import org.springframework.web.client.RestTemplate; import java.net.URI; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_CONFIG; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; package io.spring.cloud.samples.brewery.bottling; @Slf4j class BottlerService { private final BottlingWorker bottlingWorker; private final PresentingClient presentingClient; private final RestTemplate restTemplate; private final AsyncRestTemplate asyncRestTemplate; private final Tracer tracer; public BottlerService(BottlingWorker bottlingWorker, PresentingClient presentingClient, RestTemplate restTemplate, AsyncRestTemplate asyncRestTemplate, Tracer tracer) { this.bottlingWorker = bottlingWorker; this.presentingClient = presentingClient; this.restTemplate = restTemplate; this.asyncRestTemplate = asyncRestTemplate; this.tracer = tracer; } /** * [SLEUTH] HystrixCommand - Javanica integration */ @HystrixCommand void bottle(Wort wort, String processId) { log.info("I'm inside bottling"); Span span = tracer.createSpan("inside_bottling"); try { notifyPresenting(processId);
bottlingWorker.bottleBeer(wort.getWort(), processId, TEST_CONFIG.get());
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlerService.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.http.RequestEntity; import org.springframework.web.client.AsyncRestTemplate; import org.springframework.web.client.RestTemplate; import java.net.URI; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_CONFIG; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
log.info("I'm inside bottling"); Span span = tracer.createSpan("inside_bottling"); try { notifyPresenting(processId); bottlingWorker.bottleBeer(wort.getWort(), processId, TEST_CONFIG.get()); } finally { tracer.close(span); } } void notifyPresenting(String processId) { log.info("I'm inside bottling. Notifying presenting"); switch (TEST_CONFIG.get().getTestCommunicationType()) { case FEIGN: callPresentingViaFeign(processId); break; default: useRestTemplateToCallPresenting(processId); } } private void callPresentingViaFeign(String processId) { presentingClient.bottlingFeed(processId, FEIGN.name()); } /** * [SLEUTH] AsyncRestTemplate with sync @LoadBalanced RestTemplate */ private void useRestTemplateToCallPresenting(String processId) { log.info("Notifying presenting about beer. Process id [{}]", processId);
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlerService.java import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.http.RequestEntity; import org.springframework.web.client.AsyncRestTemplate; import org.springframework.web.client.RestTemplate; import java.net.URI; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_CONFIG; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; log.info("I'm inside bottling"); Span span = tracer.createSpan("inside_bottling"); try { notifyPresenting(processId); bottlingWorker.bottleBeer(wort.getWort(), processId, TEST_CONFIG.get()); } finally { tracer.close(span); } } void notifyPresenting(String processId) { log.info("I'm inside bottling. Notifying presenting"); switch (TEST_CONFIG.get().getTestCommunicationType()) { case FEIGN: callPresentingViaFeign(processId); break; default: useRestTemplateToCallPresenting(processId); } } private void callPresentingViaFeign(String processId) { presentingClient.bottlingFeed(processId, FEIGN.name()); } /** * [SLEUTH] AsyncRestTemplate with sync @LoadBalanced RestTemplate */ private void useRestTemplateToCallPresenting(String processId) { log.info("Notifying presenting about beer. Process id [{}]", processId);
RequestEntity requestEntity = requestEntity()
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlerService.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // }
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.http.RequestEntity; import org.springframework.web.client.AsyncRestTemplate; import org.springframework.web.client.RestTemplate; import java.net.URI; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_CONFIG; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity;
try { notifyPresenting(processId); bottlingWorker.bottleBeer(wort.getWort(), processId, TEST_CONFIG.get()); } finally { tracer.close(span); } } void notifyPresenting(String processId) { log.info("I'm inside bottling. Notifying presenting"); switch (TEST_CONFIG.get().getTestCommunicationType()) { case FEIGN: callPresentingViaFeign(processId); break; default: useRestTemplateToCallPresenting(processId); } } private void callPresentingViaFeign(String processId) { presentingClient.bottlingFeed(processId, FEIGN.name()); } /** * [SLEUTH] AsyncRestTemplate with sync @LoadBalanced RestTemplate */ private void useRestTemplateToCallPresenting(String processId) { log.info("Notifying presenting about beer. Process id [{}]", processId); RequestEntity requestEntity = requestEntity() .processId(processId)
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Wort.java // @Data // public class Wort { // private int wort; // // public Wort(int wort) { // this.wort = wort; // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final ThreadLocal<TestConfigurationHolder> TEST_CONFIG = new ThreadLocal<>(); // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestRequestEntityBuilder.java // public static TestRequestEntityBuilder requestEntity() { // return new TestRequestEntityBuilder(); // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlerService.java import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import io.spring.cloud.samples.brewery.common.model.Version; import io.spring.cloud.samples.brewery.common.model.Wort; import lombok.extern.slf4j.Slf4j; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpMethod; import org.springframework.http.RequestEntity; import org.springframework.web.client.AsyncRestTemplate; import org.springframework.web.client.RestTemplate; import java.net.URI; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_CONFIG; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; import static io.spring.cloud.samples.brewery.common.TestRequestEntityBuilder.requestEntity; try { notifyPresenting(processId); bottlingWorker.bottleBeer(wort.getWort(), processId, TEST_CONFIG.get()); } finally { tracer.close(span); } } void notifyPresenting(String processId) { log.info("I'm inside bottling. Notifying presenting"); switch (TEST_CONFIG.get().getTestCommunicationType()) { case FEIGN: callPresentingViaFeign(processId); break; default: useRestTemplateToCallPresenting(processId); } } private void callPresentingViaFeign(String processId) { presentingClient.bottlingFeed(processId, FEIGN.name()); } /** * [SLEUTH] AsyncRestTemplate with sync @LoadBalanced RestTemplate */ private void useRestTemplateToCallPresenting(String processId) { log.info("Notifying presenting about beer. Process id [{}]", processId); RequestEntity requestEntity = requestEntity() .processId(processId)
.contentTypeVersion(Version.PRESENTING_V1)
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/PresentingClient.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE";
import io.spring.cloud.samples.brewery.common.model.Version; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME; import static org.springframework.web.bind.annotation.RequestMethod.PUT;
package io.spring.cloud.samples.brewery.bottling; @FeignClient(Collaborators.PRESENTING) @RequestMapping("/feed") interface PresentingClient { @RequestMapping( value = "/bottles/{bottles}",
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/PresentingClient.java import io.spring.cloud.samples.brewery.common.model.Version; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME; import static org.springframework.web.bind.annotation.RequestMethod.PUT; package io.spring.cloud.samples.brewery.bottling; @FeignClient(Collaborators.PRESENTING) @RequestMapping("/feed") interface PresentingClient { @RequestMapping( value = "/bottles/{bottles}",
produces = Version.PRESENTING_V1,
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/PresentingClient.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE";
import io.spring.cloud.samples.brewery.common.model.Version; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME; import static org.springframework.web.bind.annotation.RequestMethod.PUT;
package io.spring.cloud.samples.brewery.bottling; @FeignClient(Collaborators.PRESENTING) @RequestMapping("/feed") interface PresentingClient { @RequestMapping( value = "/bottles/{bottles}", produces = Version.PRESENTING_V1, consumes = Version.PRESENTING_V1, method = PUT) String updateBottles(@PathVariable("bottles") int bottles, @RequestHeader("PROCESS-ID") String processId,
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Version.java // public class Version { // public static final String BREWING_V1 = "application/vnd.io.spring.cloud.brewing.v1+json"; // public static final String PRESENTING_V1 = "application/vnd.io.spring.cloud.presenting.v1+json"; // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/PresentingClient.java import io.spring.cloud.samples.brewery.common.model.Version; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME; import static org.springframework.web.bind.annotation.RequestMethod.PUT; package io.spring.cloud.samples.brewery.bottling; @FeignClient(Collaborators.PRESENTING) @RequestMapping("/feed") interface PresentingClient { @RequestMapping( value = "/bottles/{bottles}", produces = Version.PRESENTING_V1, consumes = Version.PRESENTING_V1, method = PUT) String updateBottles(@PathVariable("bottles") int bottles, @RequestHeader("PROCESS-ID") String processId,
@RequestHeader(TEST_COMMUNICATION_TYPE_HEADER_NAME) String testCommunicationType);
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/MaturingServiceUpdater.java
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // }
import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import lombok.extern.slf4j.Slf4j; import org.springframework.web.client.RestTemplate; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN;
package io.spring.cloud.samples.brewery.aggregating; @Slf4j class MaturingServiceUpdater { private final IngredientsProperties ingredientsProperties; private final IngredientWarehouse ingredientWarehouse;
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/MaturingServiceUpdater.java import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import lombok.extern.slf4j.Slf4j; import org.springframework.web.client.RestTemplate; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; package io.spring.cloud.samples.brewery.aggregating; @Slf4j class MaturingServiceUpdater { private final IngredientsProperties ingredientsProperties; private final IngredientWarehouse ingredientWarehouse;
private final MaturingService maturingService;
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/MaturingServiceUpdater.java
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // }
import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import lombok.extern.slf4j.Slf4j; import org.springframework.web.client.RestTemplate; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN;
package io.spring.cloud.samples.brewery.aggregating; @Slf4j class MaturingServiceUpdater { private final IngredientsProperties ingredientsProperties; private final IngredientWarehouse ingredientWarehouse; private final MaturingService maturingService; private final RestTemplate restTemplate;
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/MaturingServiceUpdater.java import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import lombok.extern.slf4j.Slf4j; import org.springframework.web.client.RestTemplate; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; package io.spring.cloud.samples.brewery.aggregating; @Slf4j class MaturingServiceUpdater { private final IngredientsProperties ingredientsProperties; private final IngredientWarehouse ingredientWarehouse; private final MaturingService maturingService; private final RestTemplate restTemplate;
private final EventGateway eventGateway;
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/MaturingServiceUpdater.java
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // }
import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import lombok.extern.slf4j.Slf4j; import org.springframework.web.client.RestTemplate; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN;
package io.spring.cloud.samples.brewery.aggregating; @Slf4j class MaturingServiceUpdater { private final IngredientsProperties ingredientsProperties; private final IngredientWarehouse ingredientWarehouse; private final MaturingService maturingService; private final RestTemplate restTemplate; private final EventGateway eventGateway; public MaturingServiceUpdater(IngredientsProperties ingredientsProperties, IngredientWarehouse ingredientWarehouse, MaturingService maturingService, RestTemplate restTemplate, EventGateway eventGateway) { this.ingredientsProperties = ingredientsProperties; this.ingredientWarehouse = ingredientWarehouse; this.maturingService = maturingService; this.restTemplate = restTemplate; this.eventGateway = eventGateway; }
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/MaturingServiceUpdater.java import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import lombok.extern.slf4j.Slf4j; import org.springframework.web.client.RestTemplate; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; package io.spring.cloud.samples.brewery.aggregating; @Slf4j class MaturingServiceUpdater { private final IngredientsProperties ingredientsProperties; private final IngredientWarehouse ingredientWarehouse; private final MaturingService maturingService; private final RestTemplate restTemplate; private final EventGateway eventGateway; public MaturingServiceUpdater(IngredientsProperties ingredientsProperties, IngredientWarehouse ingredientWarehouse, MaturingService maturingService, RestTemplate restTemplate, EventGateway eventGateway) { this.ingredientsProperties = ingredientsProperties; this.ingredientWarehouse = ingredientWarehouse; this.maturingService = maturingService; this.restTemplate = restTemplate; this.eventGateway = eventGateway; }
public Ingredients updateIfLimitReached(Ingredients ingredients, String processId) {
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/MaturingServiceUpdater.java
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // }
import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import lombok.extern.slf4j.Slf4j; import org.springframework.web.client.RestTemplate; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN;
package io.spring.cloud.samples.brewery.aggregating; @Slf4j class MaturingServiceUpdater { private final IngredientsProperties ingredientsProperties; private final IngredientWarehouse ingredientWarehouse; private final MaturingService maturingService; private final RestTemplate restTemplate; private final EventGateway eventGateway; public MaturingServiceUpdater(IngredientsProperties ingredientsProperties, IngredientWarehouse ingredientWarehouse, MaturingService maturingService, RestTemplate restTemplate, EventGateway eventGateway) { this.ingredientsProperties = ingredientsProperties; this.ingredientWarehouse = ingredientWarehouse; this.maturingService = maturingService; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } public Ingredients updateIfLimitReached(Ingredients ingredients, String processId) { if (ingredientsMatchTheThreshold(ingredients)) { log.info("Ingredients match the threshold [{}] - time to notify the maturing service!", ingredientsProperties.getThreshold());
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/MaturingServiceUpdater.java import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import lombok.extern.slf4j.Slf4j; import org.springframework.web.client.RestTemplate; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; package io.spring.cloud.samples.brewery.aggregating; @Slf4j class MaturingServiceUpdater { private final IngredientsProperties ingredientsProperties; private final IngredientWarehouse ingredientWarehouse; private final MaturingService maturingService; private final RestTemplate restTemplate; private final EventGateway eventGateway; public MaturingServiceUpdater(IngredientsProperties ingredientsProperties, IngredientWarehouse ingredientWarehouse, MaturingService maturingService, RestTemplate restTemplate, EventGateway eventGateway) { this.ingredientsProperties = ingredientsProperties; this.ingredientWarehouse = ingredientWarehouse; this.maturingService = maturingService; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } public Ingredients updateIfLimitReached(Ingredients ingredients, String processId) { if (ingredientsMatchTheThreshold(ingredients)) { log.info("Ingredients match the threshold [{}] - time to notify the maturing service!", ingredientsProperties.getThreshold());
eventGateway.emitEvent(Event.builder().eventType(EventType.BREWING_STARTED).processId(processId).build());
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/MaturingServiceUpdater.java
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // }
import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import lombok.extern.slf4j.Slf4j; import org.springframework.web.client.RestTemplate; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN;
package io.spring.cloud.samples.brewery.aggregating; @Slf4j class MaturingServiceUpdater { private final IngredientsProperties ingredientsProperties; private final IngredientWarehouse ingredientWarehouse; private final MaturingService maturingService; private final RestTemplate restTemplate; private final EventGateway eventGateway; public MaturingServiceUpdater(IngredientsProperties ingredientsProperties, IngredientWarehouse ingredientWarehouse, MaturingService maturingService, RestTemplate restTemplate, EventGateway eventGateway) { this.ingredientsProperties = ingredientsProperties; this.ingredientWarehouse = ingredientWarehouse; this.maturingService = maturingService; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } public Ingredients updateIfLimitReached(Ingredients ingredients, String processId) { if (ingredientsMatchTheThreshold(ingredients)) { log.info("Ingredients match the threshold [{}] - time to notify the maturing service!", ingredientsProperties.getThreshold());
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/MaturingServiceUpdater.java import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import lombok.extern.slf4j.Slf4j; import org.springframework.web.client.RestTemplate; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; package io.spring.cloud.samples.brewery.aggregating; @Slf4j class MaturingServiceUpdater { private final IngredientsProperties ingredientsProperties; private final IngredientWarehouse ingredientWarehouse; private final MaturingService maturingService; private final RestTemplate restTemplate; private final EventGateway eventGateway; public MaturingServiceUpdater(IngredientsProperties ingredientsProperties, IngredientWarehouse ingredientWarehouse, MaturingService maturingService, RestTemplate restTemplate, EventGateway eventGateway) { this.ingredientsProperties = ingredientsProperties; this.ingredientWarehouse = ingredientWarehouse; this.maturingService = maturingService; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } public Ingredients updateIfLimitReached(Ingredients ingredients, String processId) { if (ingredientsMatchTheThreshold(ingredients)) { log.info("Ingredients match the threshold [{}] - time to notify the maturing service!", ingredientsProperties.getThreshold());
eventGateway.emitEvent(Event.builder().eventType(EventType.BREWING_STARTED).processId(processId).build());
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/MaturingServiceUpdater.java
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // }
import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import lombok.extern.slf4j.Slf4j; import org.springframework.web.client.RestTemplate; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN;
private final EventGateway eventGateway; public MaturingServiceUpdater(IngredientsProperties ingredientsProperties, IngredientWarehouse ingredientWarehouse, MaturingService maturingService, RestTemplate restTemplate, EventGateway eventGateway) { this.ingredientsProperties = ingredientsProperties; this.ingredientWarehouse = ingredientWarehouse; this.maturingService = maturingService; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } public Ingredients updateIfLimitReached(Ingredients ingredients, String processId) { if (ingredientsMatchTheThreshold(ingredients)) { log.info("Ingredients match the threshold [{}] - time to notify the maturing service!", ingredientsProperties.getThreshold()); eventGateway.emitEvent(Event.builder().eventType(EventType.BREWING_STARTED).processId(processId).build()); notifyMaturingService(ingredients, processId); ingredientWarehouse.useIngredients(ingredientsProperties.getThreshold()); } else { log.warn("Ingredients DO NOT match the threshold [{}]. If you're clicking manually then " + "everything is fine. If you're running the tests then most likely Config Server is not available " + "and threshold value is wrong.", ingredientsProperties.getThreshold()); } Ingredients currentState = ingredientWarehouse.getCurrentState(); log.info("Current state of ingredients is [{}]", currentState); return currentState; } private boolean ingredientsMatchTheThreshold(Ingredients ingredients) {
// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/common/MaturingService.java // public interface MaturingService { // void distributeIngredients(Ingredients ingredients, String processId, // String testCommunicationType); // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java // @ToString // public class Ingredients { // // public Ingredients() { // } // // public Ingredients(Iterable<Ingredient> ingredients) { // this.ingredients = Lists.newArrayList(ingredients); // } // // public List<Ingredient> ingredients = Lists.newArrayList(); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventGateway.java // @MessagingGateway // public interface EventGateway { // // @Gateway(requestChannel=EventSource.OUTPUT) // void emitEvent(Event event); // // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventType.java // public enum EventType { // INGREDIENTS_ORDERED, // BREWING_STARTED, // BEER_MATURED, // BEER_BOTTLED // } // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/MaturingServiceUpdater.java import io.spring.cloud.samples.brewery.common.MaturingService; import io.spring.cloud.samples.brewery.common.model.IngredientType; import io.spring.cloud.samples.brewery.common.model.Ingredients; import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventGateway; import io.spring.cloud.samples.brewery.common.events.EventType; import lombok.extern.slf4j.Slf4j; import org.springframework.web.client.RestTemplate; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TestCommunicationType.FEIGN; private final EventGateway eventGateway; public MaturingServiceUpdater(IngredientsProperties ingredientsProperties, IngredientWarehouse ingredientWarehouse, MaturingService maturingService, RestTemplate restTemplate, EventGateway eventGateway) { this.ingredientsProperties = ingredientsProperties; this.ingredientWarehouse = ingredientWarehouse; this.maturingService = maturingService; this.restTemplate = restTemplate; this.eventGateway = eventGateway; } public Ingredients updateIfLimitReached(Ingredients ingredients, String processId) { if (ingredientsMatchTheThreshold(ingredients)) { log.info("Ingredients match the threshold [{}] - time to notify the maturing service!", ingredientsProperties.getThreshold()); eventGateway.emitEvent(Event.builder().eventType(EventType.BREWING_STARTED).processId(processId).build()); notifyMaturingService(ingredients, processId); ingredientWarehouse.useIngredients(ingredientsProperties.getThreshold()); } else { log.warn("Ingredients DO NOT match the threshold [{}]. If you're clicking manually then " + "everything is fine. If you're running the tests then most likely Config Server is not available " + "and threshold value is wrong.", ingredientsProperties.getThreshold()); } Ingredients currentState = ingredientWarehouse.getCurrentState(); log.info("Current state of ingredients is [{}]", currentState); return currentState; } private boolean ingredientsMatchTheThreshold(Ingredients ingredients) {
boolean allIngredientsPresent = ingredients.ingredients.size() == IngredientType.values().length;
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsProxy.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE";
import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME;
package io.spring.cloud.samples.brewery.aggregating; @FeignClient(Collaborators.ZUUL) interface IngredientsProxy { @RequestMapping(value = "/ingredients/{ingredient}", method = RequestMethod.POST)
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsProxy.java import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME; package io.spring.cloud.samples.brewery.aggregating; @FeignClient(Collaborators.ZUUL) interface IngredientsProxy { @RequestMapping(value = "/ingredients/{ingredient}", method = RequestMethod.POST)
Ingredient ingredients(@PathVariable("ingredient") IngredientType ingredientType,
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsProxy.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE";
import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME;
package io.spring.cloud.samples.brewery.aggregating; @FeignClient(Collaborators.ZUUL) interface IngredientsProxy { @RequestMapping(value = "/ingredients/{ingredient}", method = RequestMethod.POST)
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsProxy.java import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME; package io.spring.cloud.samples.brewery.aggregating; @FeignClient(Collaborators.ZUUL) interface IngredientsProxy { @RequestMapping(value = "/ingredients/{ingredient}", method = RequestMethod.POST)
Ingredient ingredients(@PathVariable("ingredient") IngredientType ingredientType,
redhat-developer-demos/brewery
brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsProxy.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE";
import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME;
package io.spring.cloud.samples.brewery.aggregating; @FeignClient(Collaborators.ZUUL) interface IngredientsProxy { @RequestMapping(value = "/ingredients/{ingredient}", method = RequestMethod.POST) Ingredient ingredients(@PathVariable("ingredient") IngredientType ingredientType, @RequestHeader("PROCESS-ID") String processId,
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java // @Data // public class Ingredient { // private IngredientType type; // private Integer quantity; // // public Ingredient(IngredientType type, Integer quantity) { // this.type = type; // this.quantity = quantity; // } // // public Ingredient() { // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java // public enum IngredientType { // MALT, WATER, HOP, YEAST // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/TestConfigurationHolder.java // public static final String TEST_COMMUNICATION_TYPE_HEADER_NAME = "TEST-COMMUNICATION-TYPE"; // Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsProxy.java import io.spring.cloud.samples.brewery.common.model.Ingredient; import io.spring.cloud.samples.brewery.common.model.IngredientType; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import static io.spring.cloud.samples.brewery.common.TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME; package io.spring.cloud.samples.brewery.aggregating; @FeignClient(Collaborators.ZUUL) interface IngredientsProxy { @RequestMapping(value = "/ingredients/{ingredient}", method = RequestMethod.POST) Ingredient ingredients(@PathVariable("ingredient") IngredientType ingredientType, @RequestHeader("PROCESS-ID") String processId,
@RequestHeader(TEST_COMMUNICATION_TYPE_HEADER_NAME) String testCommunicationType);
redhat-developer-demos/brewery
reporting/src/main/java/io/spring/cloud/samples/brewery/reporting/EventListener.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventSink.java // public interface EventSink { // // String INPUT = "events"; // // @Input(EventSink.INPUT) // SubscribableChannel input(); // }
import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventSink; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.messaging.handler.annotation.Headers; import java.util.Map;
package io.spring.cloud.samples.brewery.reporting; @MessageEndpoint @Slf4j class EventListener { private final ReportingRepository reportingRepository; private final Tracer tracer; @Autowired public EventListener(ReportingRepository reportingRepository, Tracer tracer) { this.reportingRepository = reportingRepository; this.tracer = tracer; }
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventSink.java // public interface EventSink { // // String INPUT = "events"; // // @Input(EventSink.INPUT) // SubscribableChannel input(); // } // Path: reporting/src/main/java/io/spring/cloud/samples/brewery/reporting/EventListener.java import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventSink; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.messaging.handler.annotation.Headers; import java.util.Map; package io.spring.cloud.samples.brewery.reporting; @MessageEndpoint @Slf4j class EventListener { private final ReportingRepository reportingRepository; private final Tracer tracer; @Autowired public EventListener(ReportingRepository reportingRepository, Tracer tracer) { this.reportingRepository = reportingRepository; this.tracer = tracer; }
@ServiceActivator(inputChannel = EventSink.INPUT)
redhat-developer-demos/brewery
reporting/src/main/java/io/spring/cloud/samples/brewery/reporting/EventListener.java
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventSink.java // public interface EventSink { // // String INPUT = "events"; // // @Input(EventSink.INPUT) // SubscribableChannel input(); // }
import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventSink; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.messaging.handler.annotation.Headers; import java.util.Map;
package io.spring.cloud.samples.brewery.reporting; @MessageEndpoint @Slf4j class EventListener { private final ReportingRepository reportingRepository; private final Tracer tracer; @Autowired public EventListener(ReportingRepository reportingRepository, Tracer tracer) { this.reportingRepository = reportingRepository; this.tracer = tracer; } @ServiceActivator(inputChannel = EventSink.INPUT)
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/Event.java // @Data // public class Event implements Serializable { // private String processId; // private EventType eventType; // private LocalDateTime eventTime = LocalDateTime.now(); // // public Event(String processId, EventType eventType) { // this.processId = processId; // this.eventType = eventType; // } // // public Event() {} // // public static EventBuilder builder() { // return new EventBuilder(); // } // // public static class EventBuilder { // // private String processId; // private EventType eventType; // // public EventBuilder eventType(EventType eventType) { // this.eventType = eventType; // return this; // } // // public EventBuilder processId(String processId) { // this.processId = processId; // return this; // } // // public Event build() { // return new Event(this.processId, this.eventType); // } // // } // } // // Path: common/src/main/java/io/spring/cloud/samples/brewery/common/events/EventSink.java // public interface EventSink { // // String INPUT = "events"; // // @Input(EventSink.INPUT) // SubscribableChannel input(); // } // Path: reporting/src/main/java/io/spring/cloud/samples/brewery/reporting/EventListener.java import io.spring.cloud.samples.brewery.common.events.Event; import io.spring.cloud.samples.brewery.common.events.EventSink; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.messaging.handler.annotation.Headers; import java.util.Map; package io.spring.cloud.samples.brewery.reporting; @MessageEndpoint @Slf4j class EventListener { private final ReportingRepository reportingRepository; private final Tracer tracer; @Autowired public EventListener(ReportingRepository reportingRepository, Tracer tracer) { this.reportingRepository = reportingRepository; this.tracer = tracer; } @ServiceActivator(inputChannel = EventSink.INPUT)
public void handleEvents(Event event, @Headers Map<String, Object> headers) throws InterruptedException {
maxpowa/AdvancedHUD
src/main/java/advancedhud/AdvancedHUD.java
// Path: src/main/java/advancedhud/api/HUDRegistry.java // public class HUDRegistry { // protected static List<HudItem> hudItemList = new ArrayList<HudItem>(); // protected static boolean initialLoadComplete = false; // protected static List<HudItem> hudItemListActive = new ArrayList<HudItem>(); // // private static Logger log = LogManager.getLogger("AdvancedHUD-API"); // public static int screenWidth; // public static int screenHeight; // public static int updateCounter; // // public static void registerHudItem(HudItem hudItem) { // if (hudItem.getDefaultID() <= 25 && initialLoadComplete) { // log.info("Rejecting " + hudItem.getName() + " due to invalid ID."); // } // if (!hudItemList.contains(hudItem)) { // hudItemList.add(hudItem); // if (hudItem.isEnabledByDefault()) { // enableHudItem(hudItem); // } // } // } // // public static List<HudItem> getHudItemList() { // return hudItemList; // } // // public static void enableHudItem(HudItem hudItem) { // if (hudItemList.contains(hudItem) && !hudItemListActive.contains(hudItem)) { // hudItemListActive.add(hudItem); // } // } // // public static void disableHudItem(HudItem hudItem) { // hudItemListActive.remove(hudItem); // } // // public static List<HudItem> getActiveHudItemList() { // return hudItemListActive; // } // // public static boolean isActiveHudItem(HudItem hudItem) { // return getActiveHudItemList().contains(hudItem); // } // // public static Minecraft getMinecraftInstance() { // return Minecraft.getMinecraft(); // } // // public static String getMinecraftVersion() { // return "@MCVERSION@"; // } // // public static HudItem getHudItemByID(int id) { // for (HudItem huditem : getHudItemList()) { // if (id == huditem.getDefaultID()) // return huditem; // } // return null; // } // // public static void resetAllDefaults() { // for (HudItem huditem : HUDRegistry.getHudItemList()) { // //huditem.rotated = false; // huditem.alignment = huditem.getDefaultAlignment(); // huditem.posX = huditem.getDefaultPosX(); // huditem.posY = huditem.getDefaultPosY(); // } // } // // public static boolean checkForResize() { // Minecraft mc = getMinecraftInstance(); // // ScaledResolution scaledresolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); // if (scaledresolution.getScaledWidth() != screenWidth || scaledresolution.getScaledHeight() != screenHeight) { // if (screenWidth != 0) { // fixHudItemOffsets(scaledresolution.getScaledWidth(), scaledresolution.getScaledHeight(), screenWidth, screenHeight); // } // screenWidth = scaledresolution.getScaledWidth(); // screenHeight = scaledresolution.getScaledHeight(); // return true; // } // return false; // } // // private static void fixHudItemOffsets(int newScreenWidth, int newScreenHeight, int oldScreenWidth, int oldScreenHeight) { // for (HudItem hudItem : hudItemList) { // if (Alignment.isHorizontalCenter(hudItem.alignment)) { // int offsetX = hudItem.posX - oldScreenWidth / 2; // hudItem.posX = newScreenWidth / 2 + offsetX; // } else if (Alignment.isRight(hudItem.alignment)) { // int offsetX = hudItem.posX - oldScreenWidth; // hudItem.posX = newScreenWidth + offsetX; // } // // if (Alignment.isVerticalCenter(hudItem.alignment)) { // int offsetY = hudItem.posY - oldScreenHeight / 2; // hudItem.posY = newScreenHeight / 2 + offsetY; // } else if (Alignment.isBottom(hudItem.alignment)) { // int offsetY = hudItem.posY - oldScreenHeight; // hudItem.posY = newScreenHeight + offsetY; // } // } // } // // public static void readFromNBT(NBTTagCompound nbt) { // screenWidth = nbt.getInteger("screenWidth"); // screenHeight = nbt.getInteger("screenHeight"); // // hudItemListActive = new ArrayList<HudItem>(hudItemList); // for (HudItem hudItem : hudItemList) { // if (!nbt.hasKey(hudItem.getName())) { // disableHudItem(hudItem); // } // } // } // // public static void writeToNBT(NBTTagCompound nbt) { // nbt.setInteger("screenWidth", screenWidth); // nbt.setInteger("screenHeight", screenHeight); // // for (Object hudItem_ : hudItemListActive) { // HudItem hudItem = (HudItem) hudItem_; // nbt.setBoolean(hudItem.getName(), true); // } // // } // // public static void setInitialLoadComplete(boolean b) { // initialLoadComplete = b; // } // }
import advancedhud.api.HUDRegistry; import advancedhud.client.huditems.*; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import org.apache.logging.log4j.Logger;
package advancedhud; @Mod(modid = AdvancedHUD.MOD_ID, name = "AdvancedHUD", version = AdvancedHUD.VERSION) public class AdvancedHUD { public final static String MOD_ID = "advancedhud"; public final static String VERSION = "@VERSION@"; public final static String MC_VERSION = "@MCVERSION@"; public static Logger log; @EventHandler public void preInit(FMLPreInitializationEvent event) { log = event.getModLog(); } @EventHandler public void onInit(FMLInitializationEvent event) { FMLCommonHandler.instance().bus().register(new TickHandler()); FMLCommonHandler.instance().bus().register(new KeyRegister()); registerHUDItems(); } private void registerHUDItems() {
// Path: src/main/java/advancedhud/api/HUDRegistry.java // public class HUDRegistry { // protected static List<HudItem> hudItemList = new ArrayList<HudItem>(); // protected static boolean initialLoadComplete = false; // protected static List<HudItem> hudItemListActive = new ArrayList<HudItem>(); // // private static Logger log = LogManager.getLogger("AdvancedHUD-API"); // public static int screenWidth; // public static int screenHeight; // public static int updateCounter; // // public static void registerHudItem(HudItem hudItem) { // if (hudItem.getDefaultID() <= 25 && initialLoadComplete) { // log.info("Rejecting " + hudItem.getName() + " due to invalid ID."); // } // if (!hudItemList.contains(hudItem)) { // hudItemList.add(hudItem); // if (hudItem.isEnabledByDefault()) { // enableHudItem(hudItem); // } // } // } // // public static List<HudItem> getHudItemList() { // return hudItemList; // } // // public static void enableHudItem(HudItem hudItem) { // if (hudItemList.contains(hudItem) && !hudItemListActive.contains(hudItem)) { // hudItemListActive.add(hudItem); // } // } // // public static void disableHudItem(HudItem hudItem) { // hudItemListActive.remove(hudItem); // } // // public static List<HudItem> getActiveHudItemList() { // return hudItemListActive; // } // // public static boolean isActiveHudItem(HudItem hudItem) { // return getActiveHudItemList().contains(hudItem); // } // // public static Minecraft getMinecraftInstance() { // return Minecraft.getMinecraft(); // } // // public static String getMinecraftVersion() { // return "@MCVERSION@"; // } // // public static HudItem getHudItemByID(int id) { // for (HudItem huditem : getHudItemList()) { // if (id == huditem.getDefaultID()) // return huditem; // } // return null; // } // // public static void resetAllDefaults() { // for (HudItem huditem : HUDRegistry.getHudItemList()) { // //huditem.rotated = false; // huditem.alignment = huditem.getDefaultAlignment(); // huditem.posX = huditem.getDefaultPosX(); // huditem.posY = huditem.getDefaultPosY(); // } // } // // public static boolean checkForResize() { // Minecraft mc = getMinecraftInstance(); // // ScaledResolution scaledresolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); // if (scaledresolution.getScaledWidth() != screenWidth || scaledresolution.getScaledHeight() != screenHeight) { // if (screenWidth != 0) { // fixHudItemOffsets(scaledresolution.getScaledWidth(), scaledresolution.getScaledHeight(), screenWidth, screenHeight); // } // screenWidth = scaledresolution.getScaledWidth(); // screenHeight = scaledresolution.getScaledHeight(); // return true; // } // return false; // } // // private static void fixHudItemOffsets(int newScreenWidth, int newScreenHeight, int oldScreenWidth, int oldScreenHeight) { // for (HudItem hudItem : hudItemList) { // if (Alignment.isHorizontalCenter(hudItem.alignment)) { // int offsetX = hudItem.posX - oldScreenWidth / 2; // hudItem.posX = newScreenWidth / 2 + offsetX; // } else if (Alignment.isRight(hudItem.alignment)) { // int offsetX = hudItem.posX - oldScreenWidth; // hudItem.posX = newScreenWidth + offsetX; // } // // if (Alignment.isVerticalCenter(hudItem.alignment)) { // int offsetY = hudItem.posY - oldScreenHeight / 2; // hudItem.posY = newScreenHeight / 2 + offsetY; // } else if (Alignment.isBottom(hudItem.alignment)) { // int offsetY = hudItem.posY - oldScreenHeight; // hudItem.posY = newScreenHeight + offsetY; // } // } // } // // public static void readFromNBT(NBTTagCompound nbt) { // screenWidth = nbt.getInteger("screenWidth"); // screenHeight = nbt.getInteger("screenHeight"); // // hudItemListActive = new ArrayList<HudItem>(hudItemList); // for (HudItem hudItem : hudItemList) { // if (!nbt.hasKey(hudItem.getName())) { // disableHudItem(hudItem); // } // } // } // // public static void writeToNBT(NBTTagCompound nbt) { // nbt.setInteger("screenWidth", screenWidth); // nbt.setInteger("screenHeight", screenHeight); // // for (Object hudItem_ : hudItemListActive) { // HudItem hudItem = (HudItem) hudItem_; // nbt.setBoolean(hudItem.getName(), true); // } // // } // // public static void setInitialLoadComplete(boolean b) { // initialLoadComplete = b; // } // } // Path: src/main/java/advancedhud/AdvancedHUD.java import advancedhud.api.HUDRegistry; import advancedhud.client.huditems.*; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import org.apache.logging.log4j.Logger; package advancedhud; @Mod(modid = AdvancedHUD.MOD_ID, name = "AdvancedHUD", version = AdvancedHUD.VERSION) public class AdvancedHUD { public final static String MOD_ID = "advancedhud"; public final static String VERSION = "@VERSION@"; public final static String MC_VERSION = "@MCVERSION@"; public static Logger log; @EventHandler public void preInit(FMLPreInitializationEvent event) { log = event.getModLog(); } @EventHandler public void onInit(FMLInitializationEvent event) { FMLCommonHandler.instance().bus().register(new TickHandler()); FMLCommonHandler.instance().bus().register(new KeyRegister()); registerHUDItems(); } private void registerHUDItems() {
HUDRegistry.registerHudItem(new HudItemHotbar());
maxpowa/AdvancedHUD
src/main/java/advancedhud/KeyRegister.java
// Path: src/main/java/advancedhud/client/ui/GuiAdvancedHUDConfiguration.java // public class GuiAdvancedHUDConfiguration extends GuiScreen { // // private static boolean asMount = false; // private static boolean help = true; // // @Override // public void initGui() { // super.initGui(); // addButtons(); // } // // @SuppressWarnings("unchecked") // private void addButtons() { // buttonList.clear(); // buttonList.add(new GuiButton(-1, HUDRegistry.screenWidth - 30, 10, 20, 20, "X")); // for (HudItem huditem : HUDRegistry.getHudItemList()) { // if (asMount && huditem.shouldDrawOnMount()) { // buttonList.add(new GuiHudItemButton(huditem.getDefaultID(), huditem.posX, huditem.posY, huditem.getWidth(), huditem.getHeight(), huditem.getButtonLabel())); // } else if (!asMount && huditem.shouldDrawAsPlayer()) { // buttonList.add(new GuiHudItemButton(huditem.getDefaultID(), huditem.posX, huditem.posY, huditem.getWidth(), huditem.getHeight(), huditem.getButtonLabel())); // } // } // } // // @Override // public void drawScreen(int par1, int par2, float par3) { // this.drawDefaultBackground(); // // if (!HUDRegistry.checkForResize()) { // initGui(); // } // // if (help) { // drawCenteredString(mc.fontRenderer, "LEFT CLICK to reposition, RIGHT CLICK to change settings", width / 2, 17, 0xFFFFFF); // drawCenteredString(mc.fontRenderer, "ESCAPE to cancel, R to reset all", width / 2, 27, 0xFFFFFF); // drawCenteredString(mc.fontRenderer, "M to change to" + (asMount ? " player " : " mount ") + "HUD", width / 2, 37, 0xFFFFFF); // } // // super.drawScreen(par1, par2, par3); // } // // /** // * Fired when a key is typed. This is the equivalent of // * KeyListener.keyTyped(KeyEvent e). // */ // @Override // protected void keyTyped(char par1, int par2) { // if (par2 == 19) { // HUDRegistry.resetAllDefaults(); // initGui(); // } else if (par2 == Keyboard.KEY_M) { // asMount = !asMount; // initGui(); // } else if (par2 == Keyboard.KEY_F1) { // help = !help; // } // SaveController.saveConfig("config"); // super.keyTyped(par1, par2); // } // // @Override // protected void actionPerformed(GuiButton par1GuiButton) { // if (par1GuiButton.id == -1) { // mc.displayGuiScreen(null); // SaveController.saveConfig("config"); // } // if (par1GuiButton instanceof GuiHudItemButton) { // HudItem hudItem = HUDRegistry.getHudItemByID(par1GuiButton.id); // if (hudItem != null && hudItem.isMoveable()) { // Minecraft.getMinecraft().displayGuiScreen(new GuiScreenReposition(this, hudItem)); // } // } // super.actionPerformed(par1GuiButton); // } // // @Override // public void mouseClicked(int i, int j, int mouseButton) { // if (mouseButton == 1) { // for (Object button : buttonList) { // GuiButton guibutton = (GuiButton) button; // // if (guibutton.mousePressed(mc, i, j)) { // mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); // HudItem hudItem = HUDRegistry.getHudItemByID(guibutton.id); // if (hudItem != null) { // Minecraft.getMinecraft().displayGuiScreen(hudItem.getConfigScreen()); // } // } // } // } // super.mouseClicked(i, j, mouseButton); // } // // }
import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; import org.lwjgl.input.Keyboard; import advancedhud.client.ui.GuiAdvancedHUDConfiguration; import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent;
package advancedhud; public class KeyRegister { public static KeyBinding config = new KeyBinding("\u00a7aAdvancedHUD Config", Keyboard.KEY_H, "key.categories.misc"); static { ClientRegistry.registerKeyBinding(config); } @SubscribeEvent public void KeyInputEvent(KeyInputEvent event) { Minecraft mc = Minecraft.getMinecraft(); if (config.isPressed() && mc.currentScreen == null) {
// Path: src/main/java/advancedhud/client/ui/GuiAdvancedHUDConfiguration.java // public class GuiAdvancedHUDConfiguration extends GuiScreen { // // private static boolean asMount = false; // private static boolean help = true; // // @Override // public void initGui() { // super.initGui(); // addButtons(); // } // // @SuppressWarnings("unchecked") // private void addButtons() { // buttonList.clear(); // buttonList.add(new GuiButton(-1, HUDRegistry.screenWidth - 30, 10, 20, 20, "X")); // for (HudItem huditem : HUDRegistry.getHudItemList()) { // if (asMount && huditem.shouldDrawOnMount()) { // buttonList.add(new GuiHudItemButton(huditem.getDefaultID(), huditem.posX, huditem.posY, huditem.getWidth(), huditem.getHeight(), huditem.getButtonLabel())); // } else if (!asMount && huditem.shouldDrawAsPlayer()) { // buttonList.add(new GuiHudItemButton(huditem.getDefaultID(), huditem.posX, huditem.posY, huditem.getWidth(), huditem.getHeight(), huditem.getButtonLabel())); // } // } // } // // @Override // public void drawScreen(int par1, int par2, float par3) { // this.drawDefaultBackground(); // // if (!HUDRegistry.checkForResize()) { // initGui(); // } // // if (help) { // drawCenteredString(mc.fontRenderer, "LEFT CLICK to reposition, RIGHT CLICK to change settings", width / 2, 17, 0xFFFFFF); // drawCenteredString(mc.fontRenderer, "ESCAPE to cancel, R to reset all", width / 2, 27, 0xFFFFFF); // drawCenteredString(mc.fontRenderer, "M to change to" + (asMount ? " player " : " mount ") + "HUD", width / 2, 37, 0xFFFFFF); // } // // super.drawScreen(par1, par2, par3); // } // // /** // * Fired when a key is typed. This is the equivalent of // * KeyListener.keyTyped(KeyEvent e). // */ // @Override // protected void keyTyped(char par1, int par2) { // if (par2 == 19) { // HUDRegistry.resetAllDefaults(); // initGui(); // } else if (par2 == Keyboard.KEY_M) { // asMount = !asMount; // initGui(); // } else if (par2 == Keyboard.KEY_F1) { // help = !help; // } // SaveController.saveConfig("config"); // super.keyTyped(par1, par2); // } // // @Override // protected void actionPerformed(GuiButton par1GuiButton) { // if (par1GuiButton.id == -1) { // mc.displayGuiScreen(null); // SaveController.saveConfig("config"); // } // if (par1GuiButton instanceof GuiHudItemButton) { // HudItem hudItem = HUDRegistry.getHudItemByID(par1GuiButton.id); // if (hudItem != null && hudItem.isMoveable()) { // Minecraft.getMinecraft().displayGuiScreen(new GuiScreenReposition(this, hudItem)); // } // } // super.actionPerformed(par1GuiButton); // } // // @Override // public void mouseClicked(int i, int j, int mouseButton) { // if (mouseButton == 1) { // for (Object button : buttonList) { // GuiButton guibutton = (GuiButton) button; // // if (guibutton.mousePressed(mc, i, j)) { // mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); // HudItem hudItem = HUDRegistry.getHudItemByID(guibutton.id); // if (hudItem != null) { // Minecraft.getMinecraft().displayGuiScreen(hudItem.getConfigScreen()); // } // } // } // } // super.mouseClicked(i, j, mouseButton); // } // // } // Path: src/main/java/advancedhud/KeyRegister.java import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; import org.lwjgl.input.Keyboard; import advancedhud.client.ui.GuiAdvancedHUDConfiguration; import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent; package advancedhud; public class KeyRegister { public static KeyBinding config = new KeyBinding("\u00a7aAdvancedHUD Config", Keyboard.KEY_H, "key.categories.misc"); static { ClientRegistry.registerKeyBinding(config); } @SubscribeEvent public void KeyInputEvent(KeyInputEvent event) { Minecraft mc = Minecraft.getMinecraft(); if (config.isPressed() && mc.currentScreen == null) {
mc.displayGuiScreen(new GuiAdvancedHUDConfiguration());
BrynCooke/totorom
totorom-tinkerpop2/src/main/java/org/jglue/totorom/internal/PathPipe.java
// Path: totorom-tinkerpop2/src/main/java/org/jglue/totorom/Path.java // public class Path extends ArrayList<Object> { // // public <T> T get(int index, Class<T> clazz) { // // T object = (T) get(index); // if(object instanceof TVertex) { // return (T) ((TVertex) object).reframe((Class)clazz); // } // if(object instanceof TEdge) { // return (T) ((TEdge) object).reframe((Class)clazz); // } // return object; // } // // }
import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; import org.jglue.totorom.Path; import com.tinkerpop.pipes.AbstractPipe; import com.tinkerpop.pipes.Pipe; import com.tinkerpop.pipes.PipeFunction; import com.tinkerpop.pipes.transform.TransformPipe;
/** * Copyright 2014-Infinity Bryn Cooke * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * This project is derived from code in the Tinkerpop project under the following licenses: * * Tinkerpop3 * http://www.apache.org/licenses/LICENSE-2.0 * * Tinkerpop2 * Copyright (c) 2009-Infinity, TinkerPop [http://tinkerpop.com] * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the TinkerPop nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL TINKERPOP BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jglue.totorom.internal; public class PathPipe<S> extends AbstractPipe<S, List> implements TransformPipe<S, List> { private final PipeFunction[] pathFunctions; public PathPipe(final PipeFunction... pathFunctions) { if (pathFunctions.length == 0) { this.pathFunctions = null; } else { this.pathFunctions = pathFunctions; } } public void setStarts(final Iterator<S> starts) { super.setStarts(starts); this.enablePath(true); } public List processNextStart() { if (this.starts instanceof Pipe) { this.starts.next(); final List path = ((Pipe) this.starts).getCurrentPath(); if (null == this.pathFunctions) { return path; } else {
// Path: totorom-tinkerpop2/src/main/java/org/jglue/totorom/Path.java // public class Path extends ArrayList<Object> { // // public <T> T get(int index, Class<T> clazz) { // // T object = (T) get(index); // if(object instanceof TVertex) { // return (T) ((TVertex) object).reframe((Class)clazz); // } // if(object instanceof TEdge) { // return (T) ((TEdge) object).reframe((Class)clazz); // } // return object; // } // // } // Path: totorom-tinkerpop2/src/main/java/org/jglue/totorom/internal/PathPipe.java import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; import org.jglue.totorom.Path; import com.tinkerpop.pipes.AbstractPipe; import com.tinkerpop.pipes.Pipe; import com.tinkerpop.pipes.PipeFunction; import com.tinkerpop.pipes.transform.TransformPipe; /** * Copyright 2014-Infinity Bryn Cooke * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * This project is derived from code in the Tinkerpop project under the following licenses: * * Tinkerpop3 * http://www.apache.org/licenses/LICENSE-2.0 * * Tinkerpop2 * Copyright (c) 2009-Infinity, TinkerPop [http://tinkerpop.com] * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the TinkerPop nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL TINKERPOP BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jglue.totorom.internal; public class PathPipe<S> extends AbstractPipe<S, List> implements TransformPipe<S, List> { private final PipeFunction[] pathFunctions; public PathPipe(final PipeFunction... pathFunctions) { if (pathFunctions.length == 0) { this.pathFunctions = null; } else { this.pathFunctions = pathFunctions; } } public void setStarts(final Iterator<S> starts) { super.setStarts(starts); this.enablePath(true); } public List processNextStart() { if (this.starts instanceof Pipe) { this.starts.next(); final List path = ((Pipe) this.starts).getCurrentPath(); if (null == this.pathFunctions) { return path; } else {
final List closedPath = new Path();
BrynCooke/totorom
totorom-tinkerpop2/src/main/java/org/jglue/totorom/TraversalImpl.java
// Path: totorom-tinkerpop2/src/main/java/org/jglue/totorom/internal/TotoromGremlinPipeline.java // public class TotoromGremlinPipeline<S, E> extends GremlinPipeline<S, E> { // // private String key; // private Object value; // private E current; // // public TotoromGremlinPipeline() { // super(); // } // // public TotoromGremlinPipeline(Object starts, boolean doQueryOptimization) { // super(starts, doQueryOptimization); // } // // public TotoromGremlinPipeline(Object starts) { // super(starts); // // } // // @Override // public GremlinPipeline<S, List> path(PipeFunction... pathFunctions) { // // return this.add(new PathPipe<Object>(FluentUtility.prepareFunctions(this.asMap, pathFunctions))); // } // // @Override // public void remove() { // if (current instanceof Element) { // ((Element) current).remove(); // current = null; // } // else { // throw new UnsupportedOperationException("Current must be an element to remove"); // } // } // // @Override // public E next() { // // current = super.next(); // return current; // } // // @Override // public GremlinPipeline<S, E> _() { // return super._(); // } // // @Override // public List<E> next(int number) { // current = null; // return super.next(number); // } // // public void removeAll() { // // super.remove(); // } // // }
import java.util.ArrayDeque; import java.util.Deque; import java.util.Iterator; import org.jglue.totorom.internal.TotoromGremlinPipeline; import com.tinkerpop.blueprints.Graph; import com.tinkerpop.gremlin.java.GremlinPipeline;
/** * Copyright 2014-Infinity Bryn Cooke * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * This project is derived from code in the Tinkerpop project under the following licenses: * * Tinkerpop3 * http://www.apache.org/licenses/LICENSE-2.0 * * Tinkerpop2 * Copyright (c) 2009-Infinity, TinkerPop [http://tinkerpop.com] * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the TinkerPop nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL TINKERPOP BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jglue.totorom; /** * The implementation of * * @author bryn * */ @SuppressWarnings("rawtypes") class TraversalImpl extends TraversalBase implements Traversal { private FramedGraph graph;
// Path: totorom-tinkerpop2/src/main/java/org/jglue/totorom/internal/TotoromGremlinPipeline.java // public class TotoromGremlinPipeline<S, E> extends GremlinPipeline<S, E> { // // private String key; // private Object value; // private E current; // // public TotoromGremlinPipeline() { // super(); // } // // public TotoromGremlinPipeline(Object starts, boolean doQueryOptimization) { // super(starts, doQueryOptimization); // } // // public TotoromGremlinPipeline(Object starts) { // super(starts); // // } // // @Override // public GremlinPipeline<S, List> path(PipeFunction... pathFunctions) { // // return this.add(new PathPipe<Object>(FluentUtility.prepareFunctions(this.asMap, pathFunctions))); // } // // @Override // public void remove() { // if (current instanceof Element) { // ((Element) current).remove(); // current = null; // } // else { // throw new UnsupportedOperationException("Current must be an element to remove"); // } // } // // @Override // public E next() { // // current = super.next(); // return current; // } // // @Override // public GremlinPipeline<S, E> _() { // return super._(); // } // // @Override // public List<E> next(int number) { // current = null; // return super.next(number); // } // // public void removeAll() { // // super.remove(); // } // // } // Path: totorom-tinkerpop2/src/main/java/org/jglue/totorom/TraversalImpl.java import java.util.ArrayDeque; import java.util.Deque; import java.util.Iterator; import org.jglue.totorom.internal.TotoromGremlinPipeline; import com.tinkerpop.blueprints.Graph; import com.tinkerpop.gremlin.java.GremlinPipeline; /** * Copyright 2014-Infinity Bryn Cooke * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * This project is derived from code in the Tinkerpop project under the following licenses: * * Tinkerpop3 * http://www.apache.org/licenses/LICENSE-2.0 * * Tinkerpop2 * Copyright (c) 2009-Infinity, TinkerPop [http://tinkerpop.com] * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the TinkerPop nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL TINKERPOP BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jglue.totorom; /** * The implementation of * * @author bryn * */ @SuppressWarnings("rawtypes") class TraversalImpl extends TraversalBase implements Traversal { private FramedGraph graph;
private TotoromGremlinPipeline pipeline;
wdawson/dropwizard-auth-example
src/main/java/wdawson/samples/dropwizard/util/jwt/dto/Jwt.java
// Path: src/main/java/wdawson/samples/dropwizard/util/jwt/exception/JwtParseException.java // public class JwtParseException extends Exception { // // public JwtParseException(String s) { // super(s); // } // // public JwtParseException(Throwable throwable) { // super(throwable); // } // // }
import com.nimbusds.jose.JWSObject; import wdawson.samples.dropwizard.util.jwt.exception.JwtParseException; import java.text.ParseException;
package wdawson.samples.dropwizard.util.jwt.dto; /** * @author Jon Todd */ public final class Jwt { private final JWSObject jwsObject; private final String jwtString; protected Jwt(JWSObject jwsObject, String jwtString) { this.jwsObject = jwsObject; this.jwtString = jwtString; }
// Path: src/main/java/wdawson/samples/dropwizard/util/jwt/exception/JwtParseException.java // public class JwtParseException extends Exception { // // public JwtParseException(String s) { // super(s); // } // // public JwtParseException(Throwable throwable) { // super(throwable); // } // // } // Path: src/main/java/wdawson/samples/dropwizard/util/jwt/dto/Jwt.java import com.nimbusds.jose.JWSObject; import wdawson.samples.dropwizard.util.jwt.exception.JwtParseException; import java.text.ParseException; package wdawson.samples.dropwizard.util.jwt.dto; /** * @author Jon Todd */ public final class Jwt { private final JWSObject jwsObject; private final String jwtString; protected Jwt(JWSObject jwsObject, String jwtString) { this.jwsObject = jwsObject; this.jwtString = jwtString; }
public static Jwt newFromString(String token) throws JwtParseException {
wdawson/dropwizard-auth-example
src/main/java/wdawson/samples/dropwizard/util/jwt/dto/JwtClaims.java
// Path: src/main/java/wdawson/samples/dropwizard/util/jwt/exception/JwtClaimException.java // public class JwtClaimException extends RuntimeException { // // public JwtClaimException(String s) { // super(s); // } // // }
import com.google.common.collect.Sets; import org.joda.time.DateTimeConstants; import wdawson.samples.dropwizard.util.jwt.exception.JwtClaimException; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set;
return this; } public JwtClaimsBuilder addAudience(String audience) { addClaim(AUDIENCE, audience); return this; } public JwtClaimsBuilder addIssuer(String issuer) { addClaim(ISSUER, issuer); return this; } public JwtClaimsBuilder addExpirationTime(Date expirationTime) { addDateClaim(EXPIRATION_TIME, expirationTime); return this; } public JwtClaimsBuilder addIssuedAt(Date issuedAt) { addDateClaim(ISSUED_AT, issuedAt); return this; } public JwtClaimsBuilder addNotBefore(Date notBefore) { addDateClaim(NOT_BEFORE, notBefore); return this; } public JwtClaimsBuilder addCustomClaim(String claim, Object value) { if (JwtClaims.RESERVED_CLAIMS.contains(claim)) {
// Path: src/main/java/wdawson/samples/dropwizard/util/jwt/exception/JwtClaimException.java // public class JwtClaimException extends RuntimeException { // // public JwtClaimException(String s) { // super(s); // } // // } // Path: src/main/java/wdawson/samples/dropwizard/util/jwt/dto/JwtClaims.java import com.google.common.collect.Sets; import org.joda.time.DateTimeConstants; import wdawson.samples.dropwizard.util.jwt.exception.JwtClaimException; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; return this; } public JwtClaimsBuilder addAudience(String audience) { addClaim(AUDIENCE, audience); return this; } public JwtClaimsBuilder addIssuer(String issuer) { addClaim(ISSUER, issuer); return this; } public JwtClaimsBuilder addExpirationTime(Date expirationTime) { addDateClaim(EXPIRATION_TIME, expirationTime); return this; } public JwtClaimsBuilder addIssuedAt(Date issuedAt) { addDateClaim(ISSUED_AT, issuedAt); return this; } public JwtClaimsBuilder addNotBefore(Date notBefore) { addDateClaim(NOT_BEFORE, notBefore); return this; } public JwtClaimsBuilder addCustomClaim(String claim, Object value) { if (JwtClaims.RESERVED_CLAIMS.contains(claim)) {
throw new JwtClaimException(String.format("Claim %s is a reserved claim", claim));
wdawson/dropwizard-auth-example
src/test/java/wdawson/samples/dropwizard/filters/TLSCertificateAuthorizationFilterTest.java
// Path: src/main/java/wdawson/samples/dropwizard/filters/TLSCertificateAuthorizationFilter.java // @VisibleForTesting // static final String X509_CERTIFICATE_ATTRIBUTE = "javax.servlet.request.X509Certificate";
import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.core.Response; import java.io.FileInputStream; import java.security.KeyStore; import java.security.cert.Certificate; import java.security.cert.X509Certificate; import static io.dropwizard.testing.ResourceHelpers.resourceFilePath; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static wdawson.samples.dropwizard.filters.TLSCertificateAuthorizationFilter.X509_CERTIFICATE_ATTRIBUTE;
@BeforeClass public static void setupClass() throws Exception { homepageCertificateChain = getCertificateChainFromKeyStore("tls/homepage-service-keystore.jks"); eventCertificateChain = getCertificateChainFromKeyStore("tls/event-service-keystore.jks"); } @After public void teardown() { reset(servletRequest, requestContext); } private static X509Certificate[] getCertificateChainFromKeyStore(String keyStoreResource) throws Exception { KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(new FileInputStream(resourceFilePath(keyStoreResource)), PASSPHRASE); Certificate[] certificateChain = keyStore.getCertificateChain("service-tls"); X509Certificate[] x509CertificateChain = new X509Certificate[certificateChain.length]; for (int i = 0; i < certificateChain.length; ++i) { assertThat(certificateChain[i]).isInstanceOf(X509Certificate.class); x509CertificateChain[i] = (X509Certificate) certificateChain[i]; } return x509CertificateChain; } @Test public void filterPassesWhenSubjectMatchesRegex() throws Exception { TLSCertificateAuthorizationFilter sut = new TLSCertificateAuthorizationFilter(REG_EX, servletRequest);
// Path: src/main/java/wdawson/samples/dropwizard/filters/TLSCertificateAuthorizationFilter.java // @VisibleForTesting // static final String X509_CERTIFICATE_ATTRIBUTE = "javax.servlet.request.X509Certificate"; // Path: src/test/java/wdawson/samples/dropwizard/filters/TLSCertificateAuthorizationFilterTest.java import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.core.Response; import java.io.FileInputStream; import java.security.KeyStore; import java.security.cert.Certificate; import java.security.cert.X509Certificate; import static io.dropwizard.testing.ResourceHelpers.resourceFilePath; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static wdawson.samples.dropwizard.filters.TLSCertificateAuthorizationFilter.X509_CERTIFICATE_ATTRIBUTE; @BeforeClass public static void setupClass() throws Exception { homepageCertificateChain = getCertificateChainFromKeyStore("tls/homepage-service-keystore.jks"); eventCertificateChain = getCertificateChainFromKeyStore("tls/event-service-keystore.jks"); } @After public void teardown() { reset(servletRequest, requestContext); } private static X509Certificate[] getCertificateChainFromKeyStore(String keyStoreResource) throws Exception { KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(new FileInputStream(resourceFilePath(keyStoreResource)), PASSPHRASE); Certificate[] certificateChain = keyStore.getCertificateChain("service-tls"); X509Certificate[] x509CertificateChain = new X509Certificate[certificateChain.length]; for (int i = 0; i < certificateChain.length; ++i) { assertThat(certificateChain[i]).isInstanceOf(X509Certificate.class); x509CertificateChain[i] = (X509Certificate) certificateChain[i]; } return x509CertificateChain; } @Test public void filterPassesWhenSubjectMatchesRegex() throws Exception { TLSCertificateAuthorizationFilter sut = new TLSCertificateAuthorizationFilter(REG_EX, servletRequest);
when(servletRequest.getAttribute(X509_CERTIFICATE_ATTRIBUTE)).thenReturn(homepageCertificateChain);
wdawson/dropwizard-auth-example
src/main/java/wdawson/samples/dropwizard/health/UserInfoHealthCheck.java
// Path: src/main/java/wdawson/samples/dropwizard/util/resources/ResourceUtils.java // public class ResourceUtils { // // /** // * Reads the lines from a resource given it's location on the classpath // * // * @param resourceName The location of the resource on the classpath // * @return The lines in the resource as a List of Strings // * @throws IllegalArgumentException If the resource could not be found or parsed // */ // public static List<String> readLinesFromResource(String resourceName) { // URL namesResourceURL = Resources.getResource(resourceName); // try { // return Resources.readLines(namesResourceURL, Charsets.UTF_8); // } catch (IOException e) { // throw new IllegalArgumentException("Some I/O error occurred when reading " + resourceName); // } // } // // }
import com.codahale.metrics.health.HealthCheck; import com.google.common.annotations.VisibleForTesting; import org.apache.commons.lang3.StringUtils; import wdawson.samples.dropwizard.util.resources.ResourceUtils; import java.util.List;
package wdawson.samples.dropwizard.health; /** * Health check for user info * * Checks that we have access to user data store * * @author wdawson */ public class UserInfoHealthCheck extends HealthCheck { private final String namesResource; private final List<String> names; public UserInfoHealthCheck(String namesResource) { this.namesResource = namesResource;
// Path: src/main/java/wdawson/samples/dropwizard/util/resources/ResourceUtils.java // public class ResourceUtils { // // /** // * Reads the lines from a resource given it's location on the classpath // * // * @param resourceName The location of the resource on the classpath // * @return The lines in the resource as a List of Strings // * @throws IllegalArgumentException If the resource could not be found or parsed // */ // public static List<String> readLinesFromResource(String resourceName) { // URL namesResourceURL = Resources.getResource(resourceName); // try { // return Resources.readLines(namesResourceURL, Charsets.UTF_8); // } catch (IOException e) { // throw new IllegalArgumentException("Some I/O error occurred when reading " + resourceName); // } // } // // } // Path: src/main/java/wdawson/samples/dropwizard/health/UserInfoHealthCheck.java import com.codahale.metrics.health.HealthCheck; import com.google.common.annotations.VisibleForTesting; import org.apache.commons.lang3.StringUtils; import wdawson.samples.dropwizard.util.resources.ResourceUtils; import java.util.List; package wdawson.samples.dropwizard.health; /** * Health check for user info * * Checks that we have access to user data store * * @author wdawson */ public class UserInfoHealthCheck extends HealthCheck { private final String namesResource; private final List<String> names; public UserInfoHealthCheck(String namesResource) { this.namesResource = namesResource;
names = ResourceUtils.readLinesFromResource(this.namesResource);
wdawson/dropwizard-auth-example
src/main/java/wdawson/samples/dropwizard/resources/UserInfoResource.java
// Path: src/main/java/wdawson/samples/dropwizard/api/UserInfo.java // public class UserInfo { // // @Min(1) // private long id; // // private String name; // // public UserInfo() { // // Jackson deserialization // } // // public UserInfo(long id, String name) { // this.id = id; // this.name = name; // } // // @JsonProperty // public long getId() { // return id; // } // // @JsonProperty // public String getName() { // return name; // } // // @Override // public boolean equals(Object o) { // if (this == o) { // return true; // } // if (o == null || getClass() != o.getClass()) { // return false; // } // UserInfo userInfo = (UserInfo) o; // return id == userInfo.id && // Objects.equals(name, userInfo.name); // } // // @Override // public int hashCode() { // return Objects.hash(id, name); // } // // @Override // public String toString() { // return "UserInfo{" + // "id=" + id + // ", name='" + name + '\'' + // '}'; // } // } // // Path: src/main/java/wdawson/samples/dropwizard/auth/Role.java // public interface Role { // String USER_READ_ONLY = "USER_READ_ONLY"; // String ADMIN = "ADMIN"; // } // // Path: src/main/java/wdawson/samples/dropwizard/auth/User.java // public final class User implements Principal { // // private final String id; // private final String orgId; // private final Set<String> roles; // // /* // * Constructors // */ // // private User(Builder builder) { // id = builder.id; // orgId = builder.orgId; // roles = builder.roles; // } // // public static Builder newBuilder() { // return new Builder(); // } // // public static Builder newBuilder(User copy) { // Builder builder = new Builder(); // builder.id = copy.id; // builder.orgId = copy.orgId; // builder.roles = copy.roles; // return builder; // } // // /* // * Implement Principal interface // */ // // @Override // public String getName() { // return id; // } // // /* // * Getters // */ // // public String getId() { // return id; // } // // public String getOrgId() { // return orgId; // } // // public Set<String> getRoles() { // return roles; // } // // /* // * Builder // */ // // public static final class Builder { // private String id; // private String orgId; // private Set<String> roles; // // private Builder() { // } // // public Builder withId(String val) { // id = val; // return this; // } // // public Builder withOrgId(String val) { // orgId = val; // return this; // } // // public Builder withRoles(Set<String> val) { // roles = val; // return this; // } // // public User build() { // return new User(this); // } // } // } // // Path: src/main/java/wdawson/samples/dropwizard/util/resources/ResourceUtils.java // public class ResourceUtils { // // /** // * Reads the lines from a resource given it's location on the classpath // * // * @param resourceName The location of the resource on the classpath // * @return The lines in the resource as a List of Strings // * @throws IllegalArgumentException If the resource could not be found or parsed // */ // public static List<String> readLinesFromResource(String resourceName) { // URL namesResourceURL = Resources.getResource(resourceName); // try { // return Resources.readLines(namesResourceURL, Charsets.UTF_8); // } catch (IOException e) { // throw new IllegalArgumentException("Some I/O error occurred when reading " + resourceName); // } // } // // }
import com.codahale.metrics.annotation.Timed; import com.google.common.annotations.VisibleForTesting; import io.dropwizard.auth.Auth; import wdawson.samples.dropwizard.api.UserInfo; import wdawson.samples.dropwizard.auth.Role; import wdawson.samples.dropwizard.auth.User; import wdawson.samples.dropwizard.util.resources.ResourceUtils; import javax.annotation.security.RolesAllowed; import javax.validation.constraints.Min; import javax.ws.rs.GET; import javax.ws.rs.NotAuthorizedException; import javax.ws.rs.NotFoundException; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.LinkedList; import java.util.List; import static java.lang.String.format;
package wdawson.samples.dropwizard.resources; /** * Resource for user info * * @author wdawson */ @Path("/users") @Produces(MediaType.APPLICATION_JSON) public class UserInfoResource { private final List<String> names; public UserInfoResource(String namesResource) {
// Path: src/main/java/wdawson/samples/dropwizard/api/UserInfo.java // public class UserInfo { // // @Min(1) // private long id; // // private String name; // // public UserInfo() { // // Jackson deserialization // } // // public UserInfo(long id, String name) { // this.id = id; // this.name = name; // } // // @JsonProperty // public long getId() { // return id; // } // // @JsonProperty // public String getName() { // return name; // } // // @Override // public boolean equals(Object o) { // if (this == o) { // return true; // } // if (o == null || getClass() != o.getClass()) { // return false; // } // UserInfo userInfo = (UserInfo) o; // return id == userInfo.id && // Objects.equals(name, userInfo.name); // } // // @Override // public int hashCode() { // return Objects.hash(id, name); // } // // @Override // public String toString() { // return "UserInfo{" + // "id=" + id + // ", name='" + name + '\'' + // '}'; // } // } // // Path: src/main/java/wdawson/samples/dropwizard/auth/Role.java // public interface Role { // String USER_READ_ONLY = "USER_READ_ONLY"; // String ADMIN = "ADMIN"; // } // // Path: src/main/java/wdawson/samples/dropwizard/auth/User.java // public final class User implements Principal { // // private final String id; // private final String orgId; // private final Set<String> roles; // // /* // * Constructors // */ // // private User(Builder builder) { // id = builder.id; // orgId = builder.orgId; // roles = builder.roles; // } // // public static Builder newBuilder() { // return new Builder(); // } // // public static Builder newBuilder(User copy) { // Builder builder = new Builder(); // builder.id = copy.id; // builder.orgId = copy.orgId; // builder.roles = copy.roles; // return builder; // } // // /* // * Implement Principal interface // */ // // @Override // public String getName() { // return id; // } // // /* // * Getters // */ // // public String getId() { // return id; // } // // public String getOrgId() { // return orgId; // } // // public Set<String> getRoles() { // return roles; // } // // /* // * Builder // */ // // public static final class Builder { // private String id; // private String orgId; // private Set<String> roles; // // private Builder() { // } // // public Builder withId(String val) { // id = val; // return this; // } // // public Builder withOrgId(String val) { // orgId = val; // return this; // } // // public Builder withRoles(Set<String> val) { // roles = val; // return this; // } // // public User build() { // return new User(this); // } // } // } // // Path: src/main/java/wdawson/samples/dropwizard/util/resources/ResourceUtils.java // public class ResourceUtils { // // /** // * Reads the lines from a resource given it's location on the classpath // * // * @param resourceName The location of the resource on the classpath // * @return The lines in the resource as a List of Strings // * @throws IllegalArgumentException If the resource could not be found or parsed // */ // public static List<String> readLinesFromResource(String resourceName) { // URL namesResourceURL = Resources.getResource(resourceName); // try { // return Resources.readLines(namesResourceURL, Charsets.UTF_8); // } catch (IOException e) { // throw new IllegalArgumentException("Some I/O error occurred when reading " + resourceName); // } // } // // } // Path: src/main/java/wdawson/samples/dropwizard/resources/UserInfoResource.java import com.codahale.metrics.annotation.Timed; import com.google.common.annotations.VisibleForTesting; import io.dropwizard.auth.Auth; import wdawson.samples.dropwizard.api.UserInfo; import wdawson.samples.dropwizard.auth.Role; import wdawson.samples.dropwizard.auth.User; import wdawson.samples.dropwizard.util.resources.ResourceUtils; import javax.annotation.security.RolesAllowed; import javax.validation.constraints.Min; import javax.ws.rs.GET; import javax.ws.rs.NotAuthorizedException; import javax.ws.rs.NotFoundException; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.LinkedList; import java.util.List; import static java.lang.String.format; package wdawson.samples.dropwizard.resources; /** * Resource for user info * * @author wdawson */ @Path("/users") @Produces(MediaType.APPLICATION_JSON) public class UserInfoResource { private final List<String> names; public UserInfoResource(String namesResource) {
names = ResourceUtils.readLinesFromResource(namesResource);
wdawson/dropwizard-auth-example
src/main/java/wdawson/samples/dropwizard/resources/UserInfoResource.java
// Path: src/main/java/wdawson/samples/dropwizard/api/UserInfo.java // public class UserInfo { // // @Min(1) // private long id; // // private String name; // // public UserInfo() { // // Jackson deserialization // } // // public UserInfo(long id, String name) { // this.id = id; // this.name = name; // } // // @JsonProperty // public long getId() { // return id; // } // // @JsonProperty // public String getName() { // return name; // } // // @Override // public boolean equals(Object o) { // if (this == o) { // return true; // } // if (o == null || getClass() != o.getClass()) { // return false; // } // UserInfo userInfo = (UserInfo) o; // return id == userInfo.id && // Objects.equals(name, userInfo.name); // } // // @Override // public int hashCode() { // return Objects.hash(id, name); // } // // @Override // public String toString() { // return "UserInfo{" + // "id=" + id + // ", name='" + name + '\'' + // '}'; // } // } // // Path: src/main/java/wdawson/samples/dropwizard/auth/Role.java // public interface Role { // String USER_READ_ONLY = "USER_READ_ONLY"; // String ADMIN = "ADMIN"; // } // // Path: src/main/java/wdawson/samples/dropwizard/auth/User.java // public final class User implements Principal { // // private final String id; // private final String orgId; // private final Set<String> roles; // // /* // * Constructors // */ // // private User(Builder builder) { // id = builder.id; // orgId = builder.orgId; // roles = builder.roles; // } // // public static Builder newBuilder() { // return new Builder(); // } // // public static Builder newBuilder(User copy) { // Builder builder = new Builder(); // builder.id = copy.id; // builder.orgId = copy.orgId; // builder.roles = copy.roles; // return builder; // } // // /* // * Implement Principal interface // */ // // @Override // public String getName() { // return id; // } // // /* // * Getters // */ // // public String getId() { // return id; // } // // public String getOrgId() { // return orgId; // } // // public Set<String> getRoles() { // return roles; // } // // /* // * Builder // */ // // public static final class Builder { // private String id; // private String orgId; // private Set<String> roles; // // private Builder() { // } // // public Builder withId(String val) { // id = val; // return this; // } // // public Builder withOrgId(String val) { // orgId = val; // return this; // } // // public Builder withRoles(Set<String> val) { // roles = val; // return this; // } // // public User build() { // return new User(this); // } // } // } // // Path: src/main/java/wdawson/samples/dropwizard/util/resources/ResourceUtils.java // public class ResourceUtils { // // /** // * Reads the lines from a resource given it's location on the classpath // * // * @param resourceName The location of the resource on the classpath // * @return The lines in the resource as a List of Strings // * @throws IllegalArgumentException If the resource could not be found or parsed // */ // public static List<String> readLinesFromResource(String resourceName) { // URL namesResourceURL = Resources.getResource(resourceName); // try { // return Resources.readLines(namesResourceURL, Charsets.UTF_8); // } catch (IOException e) { // throw new IllegalArgumentException("Some I/O error occurred when reading " + resourceName); // } // } // // }
import com.codahale.metrics.annotation.Timed; import com.google.common.annotations.VisibleForTesting; import io.dropwizard.auth.Auth; import wdawson.samples.dropwizard.api.UserInfo; import wdawson.samples.dropwizard.auth.Role; import wdawson.samples.dropwizard.auth.User; import wdawson.samples.dropwizard.util.resources.ResourceUtils; import javax.annotation.security.RolesAllowed; import javax.validation.constraints.Min; import javax.ws.rs.GET; import javax.ws.rs.NotAuthorizedException; import javax.ws.rs.NotFoundException; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.LinkedList; import java.util.List; import static java.lang.String.format;
package wdawson.samples.dropwizard.resources; /** * Resource for user info * * @author wdawson */ @Path("/users") @Produces(MediaType.APPLICATION_JSON) public class UserInfoResource { private final List<String> names; public UserInfoResource(String namesResource) { names = ResourceUtils.readLinesFromResource(namesResource); } /** * Gets the info about a user given their ID * * @param id The id of the user to fetch * @return The user */ @GET @Path(("/{id}")) @Timed
// Path: src/main/java/wdawson/samples/dropwizard/api/UserInfo.java // public class UserInfo { // // @Min(1) // private long id; // // private String name; // // public UserInfo() { // // Jackson deserialization // } // // public UserInfo(long id, String name) { // this.id = id; // this.name = name; // } // // @JsonProperty // public long getId() { // return id; // } // // @JsonProperty // public String getName() { // return name; // } // // @Override // public boolean equals(Object o) { // if (this == o) { // return true; // } // if (o == null || getClass() != o.getClass()) { // return false; // } // UserInfo userInfo = (UserInfo) o; // return id == userInfo.id && // Objects.equals(name, userInfo.name); // } // // @Override // public int hashCode() { // return Objects.hash(id, name); // } // // @Override // public String toString() { // return "UserInfo{" + // "id=" + id + // ", name='" + name + '\'' + // '}'; // } // } // // Path: src/main/java/wdawson/samples/dropwizard/auth/Role.java // public interface Role { // String USER_READ_ONLY = "USER_READ_ONLY"; // String ADMIN = "ADMIN"; // } // // Path: src/main/java/wdawson/samples/dropwizard/auth/User.java // public final class User implements Principal { // // private final String id; // private final String orgId; // private final Set<String> roles; // // /* // * Constructors // */ // // private User(Builder builder) { // id = builder.id; // orgId = builder.orgId; // roles = builder.roles; // } // // public static Builder newBuilder() { // return new Builder(); // } // // public static Builder newBuilder(User copy) { // Builder builder = new Builder(); // builder.id = copy.id; // builder.orgId = copy.orgId; // builder.roles = copy.roles; // return builder; // } // // /* // * Implement Principal interface // */ // // @Override // public String getName() { // return id; // } // // /* // * Getters // */ // // public String getId() { // return id; // } // // public String getOrgId() { // return orgId; // } // // public Set<String> getRoles() { // return roles; // } // // /* // * Builder // */ // // public static final class Builder { // private String id; // private String orgId; // private Set<String> roles; // // private Builder() { // } // // public Builder withId(String val) { // id = val; // return this; // } // // public Builder withOrgId(String val) { // orgId = val; // return this; // } // // public Builder withRoles(Set<String> val) { // roles = val; // return this; // } // // public User build() { // return new User(this); // } // } // } // // Path: src/main/java/wdawson/samples/dropwizard/util/resources/ResourceUtils.java // public class ResourceUtils { // // /** // * Reads the lines from a resource given it's location on the classpath // * // * @param resourceName The location of the resource on the classpath // * @return The lines in the resource as a List of Strings // * @throws IllegalArgumentException If the resource could not be found or parsed // */ // public static List<String> readLinesFromResource(String resourceName) { // URL namesResourceURL = Resources.getResource(resourceName); // try { // return Resources.readLines(namesResourceURL, Charsets.UTF_8); // } catch (IOException e) { // throw new IllegalArgumentException("Some I/O error occurred when reading " + resourceName); // } // } // // } // Path: src/main/java/wdawson/samples/dropwizard/resources/UserInfoResource.java import com.codahale.metrics.annotation.Timed; import com.google.common.annotations.VisibleForTesting; import io.dropwizard.auth.Auth; import wdawson.samples.dropwizard.api.UserInfo; import wdawson.samples.dropwizard.auth.Role; import wdawson.samples.dropwizard.auth.User; import wdawson.samples.dropwizard.util.resources.ResourceUtils; import javax.annotation.security.RolesAllowed; import javax.validation.constraints.Min; import javax.ws.rs.GET; import javax.ws.rs.NotAuthorizedException; import javax.ws.rs.NotFoundException; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.LinkedList; import java.util.List; import static java.lang.String.format; package wdawson.samples.dropwizard.resources; /** * Resource for user info * * @author wdawson */ @Path("/users") @Produces(MediaType.APPLICATION_JSON) public class UserInfoResource { private final List<String> names; public UserInfoResource(String namesResource) { names = ResourceUtils.readLinesFromResource(namesResource); } /** * Gets the info about a user given their ID * * @param id The id of the user to fetch * @return The user */ @GET @Path(("/{id}")) @Timed
@RolesAllowed({Role.USER_READ_ONLY, Role.ADMIN})
wdawson/dropwizard-auth-example
src/main/java/wdawson/samples/dropwizard/resources/UserInfoResource.java
// Path: src/main/java/wdawson/samples/dropwizard/api/UserInfo.java // public class UserInfo { // // @Min(1) // private long id; // // private String name; // // public UserInfo() { // // Jackson deserialization // } // // public UserInfo(long id, String name) { // this.id = id; // this.name = name; // } // // @JsonProperty // public long getId() { // return id; // } // // @JsonProperty // public String getName() { // return name; // } // // @Override // public boolean equals(Object o) { // if (this == o) { // return true; // } // if (o == null || getClass() != o.getClass()) { // return false; // } // UserInfo userInfo = (UserInfo) o; // return id == userInfo.id && // Objects.equals(name, userInfo.name); // } // // @Override // public int hashCode() { // return Objects.hash(id, name); // } // // @Override // public String toString() { // return "UserInfo{" + // "id=" + id + // ", name='" + name + '\'' + // '}'; // } // } // // Path: src/main/java/wdawson/samples/dropwizard/auth/Role.java // public interface Role { // String USER_READ_ONLY = "USER_READ_ONLY"; // String ADMIN = "ADMIN"; // } // // Path: src/main/java/wdawson/samples/dropwizard/auth/User.java // public final class User implements Principal { // // private final String id; // private final String orgId; // private final Set<String> roles; // // /* // * Constructors // */ // // private User(Builder builder) { // id = builder.id; // orgId = builder.orgId; // roles = builder.roles; // } // // public static Builder newBuilder() { // return new Builder(); // } // // public static Builder newBuilder(User copy) { // Builder builder = new Builder(); // builder.id = copy.id; // builder.orgId = copy.orgId; // builder.roles = copy.roles; // return builder; // } // // /* // * Implement Principal interface // */ // // @Override // public String getName() { // return id; // } // // /* // * Getters // */ // // public String getId() { // return id; // } // // public String getOrgId() { // return orgId; // } // // public Set<String> getRoles() { // return roles; // } // // /* // * Builder // */ // // public static final class Builder { // private String id; // private String orgId; // private Set<String> roles; // // private Builder() { // } // // public Builder withId(String val) { // id = val; // return this; // } // // public Builder withOrgId(String val) { // orgId = val; // return this; // } // // public Builder withRoles(Set<String> val) { // roles = val; // return this; // } // // public User build() { // return new User(this); // } // } // } // // Path: src/main/java/wdawson/samples/dropwizard/util/resources/ResourceUtils.java // public class ResourceUtils { // // /** // * Reads the lines from a resource given it's location on the classpath // * // * @param resourceName The location of the resource on the classpath // * @return The lines in the resource as a List of Strings // * @throws IllegalArgumentException If the resource could not be found or parsed // */ // public static List<String> readLinesFromResource(String resourceName) { // URL namesResourceURL = Resources.getResource(resourceName); // try { // return Resources.readLines(namesResourceURL, Charsets.UTF_8); // } catch (IOException e) { // throw new IllegalArgumentException("Some I/O error occurred when reading " + resourceName); // } // } // // }
import com.codahale.metrics.annotation.Timed; import com.google.common.annotations.VisibleForTesting; import io.dropwizard.auth.Auth; import wdawson.samples.dropwizard.api.UserInfo; import wdawson.samples.dropwizard.auth.Role; import wdawson.samples.dropwizard.auth.User; import wdawson.samples.dropwizard.util.resources.ResourceUtils; import javax.annotation.security.RolesAllowed; import javax.validation.constraints.Min; import javax.ws.rs.GET; import javax.ws.rs.NotAuthorizedException; import javax.ws.rs.NotFoundException; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.LinkedList; import java.util.List; import static java.lang.String.format;
package wdawson.samples.dropwizard.resources; /** * Resource for user info * * @author wdawson */ @Path("/users") @Produces(MediaType.APPLICATION_JSON) public class UserInfoResource { private final List<String> names; public UserInfoResource(String namesResource) { names = ResourceUtils.readLinesFromResource(namesResource); } /** * Gets the info about a user given their ID * * @param id The id of the user to fetch * @return The user */ @GET @Path(("/{id}")) @Timed @RolesAllowed({Role.USER_READ_ONLY, Role.ADMIN})
// Path: src/main/java/wdawson/samples/dropwizard/api/UserInfo.java // public class UserInfo { // // @Min(1) // private long id; // // private String name; // // public UserInfo() { // // Jackson deserialization // } // // public UserInfo(long id, String name) { // this.id = id; // this.name = name; // } // // @JsonProperty // public long getId() { // return id; // } // // @JsonProperty // public String getName() { // return name; // } // // @Override // public boolean equals(Object o) { // if (this == o) { // return true; // } // if (o == null || getClass() != o.getClass()) { // return false; // } // UserInfo userInfo = (UserInfo) o; // return id == userInfo.id && // Objects.equals(name, userInfo.name); // } // // @Override // public int hashCode() { // return Objects.hash(id, name); // } // // @Override // public String toString() { // return "UserInfo{" + // "id=" + id + // ", name='" + name + '\'' + // '}'; // } // } // // Path: src/main/java/wdawson/samples/dropwizard/auth/Role.java // public interface Role { // String USER_READ_ONLY = "USER_READ_ONLY"; // String ADMIN = "ADMIN"; // } // // Path: src/main/java/wdawson/samples/dropwizard/auth/User.java // public final class User implements Principal { // // private final String id; // private final String orgId; // private final Set<String> roles; // // /* // * Constructors // */ // // private User(Builder builder) { // id = builder.id; // orgId = builder.orgId; // roles = builder.roles; // } // // public static Builder newBuilder() { // return new Builder(); // } // // public static Builder newBuilder(User copy) { // Builder builder = new Builder(); // builder.id = copy.id; // builder.orgId = copy.orgId; // builder.roles = copy.roles; // return builder; // } // // /* // * Implement Principal interface // */ // // @Override // public String getName() { // return id; // } // // /* // * Getters // */ // // public String getId() { // return id; // } // // public String getOrgId() { // return orgId; // } // // public Set<String> getRoles() { // return roles; // } // // /* // * Builder // */ // // public static final class Builder { // private String id; // private String orgId; // private Set<String> roles; // // private Builder() { // } // // public Builder withId(String val) { // id = val; // return this; // } // // public Builder withOrgId(String val) { // orgId = val; // return this; // } // // public Builder withRoles(Set<String> val) { // roles = val; // return this; // } // // public User build() { // return new User(this); // } // } // } // // Path: src/main/java/wdawson/samples/dropwizard/util/resources/ResourceUtils.java // public class ResourceUtils { // // /** // * Reads the lines from a resource given it's location on the classpath // * // * @param resourceName The location of the resource on the classpath // * @return The lines in the resource as a List of Strings // * @throws IllegalArgumentException If the resource could not be found or parsed // */ // public static List<String> readLinesFromResource(String resourceName) { // URL namesResourceURL = Resources.getResource(resourceName); // try { // return Resources.readLines(namesResourceURL, Charsets.UTF_8); // } catch (IOException e) { // throw new IllegalArgumentException("Some I/O error occurred when reading " + resourceName); // } // } // // } // Path: src/main/java/wdawson/samples/dropwizard/resources/UserInfoResource.java import com.codahale.metrics.annotation.Timed; import com.google.common.annotations.VisibleForTesting; import io.dropwizard.auth.Auth; import wdawson.samples.dropwizard.api.UserInfo; import wdawson.samples.dropwizard.auth.Role; import wdawson.samples.dropwizard.auth.User; import wdawson.samples.dropwizard.util.resources.ResourceUtils; import javax.annotation.security.RolesAllowed; import javax.validation.constraints.Min; import javax.ws.rs.GET; import javax.ws.rs.NotAuthorizedException; import javax.ws.rs.NotFoundException; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.LinkedList; import java.util.List; import static java.lang.String.format; package wdawson.samples.dropwizard.resources; /** * Resource for user info * * @author wdawson */ @Path("/users") @Produces(MediaType.APPLICATION_JSON) public class UserInfoResource { private final List<String> names; public UserInfoResource(String namesResource) { names = ResourceUtils.readLinesFromResource(namesResource); } /** * Gets the info about a user given their ID * * @param id The id of the user to fetch * @return The user */ @GET @Path(("/{id}")) @Timed @RolesAllowed({Role.USER_READ_ONLY, Role.ADMIN})
public UserInfo getUser(@Min(1) @PathParam("id") long id, @Auth User user) {
wdawson/dropwizard-auth-example
src/main/java/wdawson/samples/dropwizard/resources/UserInfoResource.java
// Path: src/main/java/wdawson/samples/dropwizard/api/UserInfo.java // public class UserInfo { // // @Min(1) // private long id; // // private String name; // // public UserInfo() { // // Jackson deserialization // } // // public UserInfo(long id, String name) { // this.id = id; // this.name = name; // } // // @JsonProperty // public long getId() { // return id; // } // // @JsonProperty // public String getName() { // return name; // } // // @Override // public boolean equals(Object o) { // if (this == o) { // return true; // } // if (o == null || getClass() != o.getClass()) { // return false; // } // UserInfo userInfo = (UserInfo) o; // return id == userInfo.id && // Objects.equals(name, userInfo.name); // } // // @Override // public int hashCode() { // return Objects.hash(id, name); // } // // @Override // public String toString() { // return "UserInfo{" + // "id=" + id + // ", name='" + name + '\'' + // '}'; // } // } // // Path: src/main/java/wdawson/samples/dropwizard/auth/Role.java // public interface Role { // String USER_READ_ONLY = "USER_READ_ONLY"; // String ADMIN = "ADMIN"; // } // // Path: src/main/java/wdawson/samples/dropwizard/auth/User.java // public final class User implements Principal { // // private final String id; // private final String orgId; // private final Set<String> roles; // // /* // * Constructors // */ // // private User(Builder builder) { // id = builder.id; // orgId = builder.orgId; // roles = builder.roles; // } // // public static Builder newBuilder() { // return new Builder(); // } // // public static Builder newBuilder(User copy) { // Builder builder = new Builder(); // builder.id = copy.id; // builder.orgId = copy.orgId; // builder.roles = copy.roles; // return builder; // } // // /* // * Implement Principal interface // */ // // @Override // public String getName() { // return id; // } // // /* // * Getters // */ // // public String getId() { // return id; // } // // public String getOrgId() { // return orgId; // } // // public Set<String> getRoles() { // return roles; // } // // /* // * Builder // */ // // public static final class Builder { // private String id; // private String orgId; // private Set<String> roles; // // private Builder() { // } // // public Builder withId(String val) { // id = val; // return this; // } // // public Builder withOrgId(String val) { // orgId = val; // return this; // } // // public Builder withRoles(Set<String> val) { // roles = val; // return this; // } // // public User build() { // return new User(this); // } // } // } // // Path: src/main/java/wdawson/samples/dropwizard/util/resources/ResourceUtils.java // public class ResourceUtils { // // /** // * Reads the lines from a resource given it's location on the classpath // * // * @param resourceName The location of the resource on the classpath // * @return The lines in the resource as a List of Strings // * @throws IllegalArgumentException If the resource could not be found or parsed // */ // public static List<String> readLinesFromResource(String resourceName) { // URL namesResourceURL = Resources.getResource(resourceName); // try { // return Resources.readLines(namesResourceURL, Charsets.UTF_8); // } catch (IOException e) { // throw new IllegalArgumentException("Some I/O error occurred when reading " + resourceName); // } // } // // }
import com.codahale.metrics.annotation.Timed; import com.google.common.annotations.VisibleForTesting; import io.dropwizard.auth.Auth; import wdawson.samples.dropwizard.api.UserInfo; import wdawson.samples.dropwizard.auth.Role; import wdawson.samples.dropwizard.auth.User; import wdawson.samples.dropwizard.util.resources.ResourceUtils; import javax.annotation.security.RolesAllowed; import javax.validation.constraints.Min; import javax.ws.rs.GET; import javax.ws.rs.NotAuthorizedException; import javax.ws.rs.NotFoundException; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.LinkedList; import java.util.List; import static java.lang.String.format;
package wdawson.samples.dropwizard.resources; /** * Resource for user info * * @author wdawson */ @Path("/users") @Produces(MediaType.APPLICATION_JSON) public class UserInfoResource { private final List<String> names; public UserInfoResource(String namesResource) { names = ResourceUtils.readLinesFromResource(namesResource); } /** * Gets the info about a user given their ID * * @param id The id of the user to fetch * @return The user */ @GET @Path(("/{id}")) @Timed @RolesAllowed({Role.USER_READ_ONLY, Role.ADMIN})
// Path: src/main/java/wdawson/samples/dropwizard/api/UserInfo.java // public class UserInfo { // // @Min(1) // private long id; // // private String name; // // public UserInfo() { // // Jackson deserialization // } // // public UserInfo(long id, String name) { // this.id = id; // this.name = name; // } // // @JsonProperty // public long getId() { // return id; // } // // @JsonProperty // public String getName() { // return name; // } // // @Override // public boolean equals(Object o) { // if (this == o) { // return true; // } // if (o == null || getClass() != o.getClass()) { // return false; // } // UserInfo userInfo = (UserInfo) o; // return id == userInfo.id && // Objects.equals(name, userInfo.name); // } // // @Override // public int hashCode() { // return Objects.hash(id, name); // } // // @Override // public String toString() { // return "UserInfo{" + // "id=" + id + // ", name='" + name + '\'' + // '}'; // } // } // // Path: src/main/java/wdawson/samples/dropwizard/auth/Role.java // public interface Role { // String USER_READ_ONLY = "USER_READ_ONLY"; // String ADMIN = "ADMIN"; // } // // Path: src/main/java/wdawson/samples/dropwizard/auth/User.java // public final class User implements Principal { // // private final String id; // private final String orgId; // private final Set<String> roles; // // /* // * Constructors // */ // // private User(Builder builder) { // id = builder.id; // orgId = builder.orgId; // roles = builder.roles; // } // // public static Builder newBuilder() { // return new Builder(); // } // // public static Builder newBuilder(User copy) { // Builder builder = new Builder(); // builder.id = copy.id; // builder.orgId = copy.orgId; // builder.roles = copy.roles; // return builder; // } // // /* // * Implement Principal interface // */ // // @Override // public String getName() { // return id; // } // // /* // * Getters // */ // // public String getId() { // return id; // } // // public String getOrgId() { // return orgId; // } // // public Set<String> getRoles() { // return roles; // } // // /* // * Builder // */ // // public static final class Builder { // private String id; // private String orgId; // private Set<String> roles; // // private Builder() { // } // // public Builder withId(String val) { // id = val; // return this; // } // // public Builder withOrgId(String val) { // orgId = val; // return this; // } // // public Builder withRoles(Set<String> val) { // roles = val; // return this; // } // // public User build() { // return new User(this); // } // } // } // // Path: src/main/java/wdawson/samples/dropwizard/util/resources/ResourceUtils.java // public class ResourceUtils { // // /** // * Reads the lines from a resource given it's location on the classpath // * // * @param resourceName The location of the resource on the classpath // * @return The lines in the resource as a List of Strings // * @throws IllegalArgumentException If the resource could not be found or parsed // */ // public static List<String> readLinesFromResource(String resourceName) { // URL namesResourceURL = Resources.getResource(resourceName); // try { // return Resources.readLines(namesResourceURL, Charsets.UTF_8); // } catch (IOException e) { // throw new IllegalArgumentException("Some I/O error occurred when reading " + resourceName); // } // } // // } // Path: src/main/java/wdawson/samples/dropwizard/resources/UserInfoResource.java import com.codahale.metrics.annotation.Timed; import com.google.common.annotations.VisibleForTesting; import io.dropwizard.auth.Auth; import wdawson.samples.dropwizard.api.UserInfo; import wdawson.samples.dropwizard.auth.Role; import wdawson.samples.dropwizard.auth.User; import wdawson.samples.dropwizard.util.resources.ResourceUtils; import javax.annotation.security.RolesAllowed; import javax.validation.constraints.Min; import javax.ws.rs.GET; import javax.ws.rs.NotAuthorizedException; import javax.ws.rs.NotFoundException; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.LinkedList; import java.util.List; import static java.lang.String.format; package wdawson.samples.dropwizard.resources; /** * Resource for user info * * @author wdawson */ @Path("/users") @Produces(MediaType.APPLICATION_JSON) public class UserInfoResource { private final List<String> names; public UserInfoResource(String namesResource) { names = ResourceUtils.readLinesFromResource(namesResource); } /** * Gets the info about a user given their ID * * @param id The id of the user to fetch * @return The user */ @GET @Path(("/{id}")) @Timed @RolesAllowed({Role.USER_READ_ONLY, Role.ADMIN})
public UserInfo getUser(@Min(1) @PathParam("id") long id, @Auth User user) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/ast/CommentNode.java
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // }
import mgi.tools.jagdecs2.CodePrinter;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class CommentNode extends AbstractCodeNode { public static final int STANDART_STYLE = 0; public static final int LOGO_STYLE = 1; private String comment; private int style; public CommentNode(String comment, int style) { this.comment = comment; this.style = style; } public int numLines() { int total = 0; for (int i = 0; i < comment.length(); i++) if (comment.charAt(i) == '\n') total++; return total; } public String getComment() { return comment; } public int getStyle() { return style; } @Override
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // } // Path: src/mgi/tools/jagdecs2/ast/CommentNode.java import mgi.tools.jagdecs2.CodePrinter; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class CommentNode extends AbstractCodeNode { public static final int STANDART_STYLE = 0; public static final int LOGO_STYLE = 1; private String comment; private int style; public CommentNode(String comment, int style) { this.comment = comment; this.style = style; } public int numLines() { int total = 0; for (int i = 0; i < comment.length(); i++) if (comment.charAt(i) == '\n') total++; return total; } public String getComment() { return comment; } public int getStyle() { return style; } @Override
public void print(CodePrinter printer) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/instructions/BitConfigInstruction.java
// Path: src/mgi/tools/jagdecs2/util/BitConfigInfo.java // public class BitConfigInfo { // // private ConfigInfo base; // private String name; // // public BitConfigInfo(ConfigInfo base, String name) { // this.base = base; // this.name = name; // } // // public ConfigInfo getBase() { // return base; // } // // public String getName() { // return name; // } // // @Override // public String toString() { // return "[" + base + "," + name + "]"; // } // // } // // Path: src/mgi/tools/jagdecs2/util/InstructionInfo.java // public class InstructionInfo { // // private String name; // private int scrampledOpcode; // private int originalOpcode; // private boolean hasIntConstant; // // public InstructionInfo(String name, int scrampledop, int originalop, boolean hasIntConstant) { // this.name = name; // this.scrampledOpcode = scrampledop; // this.originalOpcode = originalop; // this.hasIntConstant = hasIntConstant; // } // // public String getName() { // return name; // } // // public int getScrampledOpcode() { // return scrampledOpcode; // } // // public int getOpcode() { // return originalOpcode; // } // // public boolean hasIntConstant() { // return hasIntConstant; // } // // @Override // public String toString() { // return name + "[" + originalOpcode + "," + scrampledOpcode + ":" + hasIntConstant + "]"; // } // // }
import mgi.tools.jagdecs2.util.BitConfigInfo; import mgi.tools.jagdecs2.util.InstructionInfo;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.instructions; public class BitConfigInstruction extends AbstractInstruction { private BitConfigInfo config; private boolean constant;
// Path: src/mgi/tools/jagdecs2/util/BitConfigInfo.java // public class BitConfigInfo { // // private ConfigInfo base; // private String name; // // public BitConfigInfo(ConfigInfo base, String name) { // this.base = base; // this.name = name; // } // // public ConfigInfo getBase() { // return base; // } // // public String getName() { // return name; // } // // @Override // public String toString() { // return "[" + base + "," + name + "]"; // } // // } // // Path: src/mgi/tools/jagdecs2/util/InstructionInfo.java // public class InstructionInfo { // // private String name; // private int scrampledOpcode; // private int originalOpcode; // private boolean hasIntConstant; // // public InstructionInfo(String name, int scrampledop, int originalop, boolean hasIntConstant) { // this.name = name; // this.scrampledOpcode = scrampledop; // this.originalOpcode = originalop; // this.hasIntConstant = hasIntConstant; // } // // public String getName() { // return name; // } // // public int getScrampledOpcode() { // return scrampledOpcode; // } // // public int getOpcode() { // return originalOpcode; // } // // public boolean hasIntConstant() { // return hasIntConstant; // } // // @Override // public String toString() { // return name + "[" + originalOpcode + "," + scrampledOpcode + ":" + hasIntConstant + "]"; // } // // } // Path: src/mgi/tools/jagdecs2/instructions/BitConfigInstruction.java import mgi.tools.jagdecs2.util.BitConfigInfo; import mgi.tools.jagdecs2.util.InstructionInfo; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.instructions; public class BitConfigInstruction extends AbstractInstruction { private BitConfigInfo config; private boolean constant;
public BitConfigInstruction(InstructionInfo info, BitConfigInfo config, boolean constant) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/ast/LoopNode.java
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // }
import mgi.tools.jagdecs2.CodePrinter;
} public VariableAssignationNode[] getPreAssigns() { return preAssigns; } public VariableAssignationNode[] getAfterAssigns() { return afterAssigns; } public void forTransform(VariableAssignationNode[] preAssigns, VariableAssignationNode[] afterAssigns) { this.type = LOOPTYPE_FOR; this.preAssigns = preAssigns; this.afterAssigns = afterAssigns; setCodeAddress(0); for (int i = 0; i < preAssigns.length; i++) { preAssigns[i].setParent(this); write(preAssigns[i]); } setCodeAddress(size() - 1); for (int i = 0; i < afterAssigns.length; i++) { afterAssigns[i].setParent(this); write(afterAssigns[i]); } } @Override
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // } // Path: src/mgi/tools/jagdecs2/ast/LoopNode.java import mgi.tools.jagdecs2.CodePrinter; } public VariableAssignationNode[] getPreAssigns() { return preAssigns; } public VariableAssignationNode[] getAfterAssigns() { return afterAssigns; } public void forTransform(VariableAssignationNode[] preAssigns, VariableAssignationNode[] afterAssigns) { this.type = LOOPTYPE_FOR; this.preAssigns = preAssigns; this.afterAssigns = afterAssigns; setCodeAddress(0); for (int i = 0; i < preAssigns.length; i++) { preAssigns[i].setParent(this); write(preAssigns[i]); } setCodeAddress(size() - 1); for (int i = 0; i < afterAssigns.length; i++) { afterAssigns[i].setParent(this); write(afterAssigns[i]); } } @Override
public void print(CodePrinter printer) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/instructions/BooleanInstruction.java
// Path: src/mgi/tools/jagdecs2/util/InstructionInfo.java // public class InstructionInfo { // // private String name; // private int scrampledOpcode; // private int originalOpcode; // private boolean hasIntConstant; // // public InstructionInfo(String name, int scrampledop, int originalop, boolean hasIntConstant) { // this.name = name; // this.scrampledOpcode = scrampledop; // this.originalOpcode = originalop; // this.hasIntConstant = hasIntConstant; // } // // public String getName() { // return name; // } // // public int getScrampledOpcode() { // return scrampledOpcode; // } // // public int getOpcode() { // return originalOpcode; // } // // public boolean hasIntConstant() { // return hasIntConstant; // } // // @Override // public String toString() { // return name + "[" + originalOpcode + "," + scrampledOpcode + ":" + hasIntConstant + "]"; // } // // }
import mgi.tools.jagdecs2.util.InstructionInfo;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.instructions; public class BooleanInstruction extends AbstractInstruction { private boolean constant;
// Path: src/mgi/tools/jagdecs2/util/InstructionInfo.java // public class InstructionInfo { // // private String name; // private int scrampledOpcode; // private int originalOpcode; // private boolean hasIntConstant; // // public InstructionInfo(String name, int scrampledop, int originalop, boolean hasIntConstant) { // this.name = name; // this.scrampledOpcode = scrampledop; // this.originalOpcode = originalop; // this.hasIntConstant = hasIntConstant; // } // // public String getName() { // return name; // } // // public int getScrampledOpcode() { // return scrampledOpcode; // } // // public int getOpcode() { // return originalOpcode; // } // // public boolean hasIntConstant() { // return hasIntConstant; // } // // @Override // public String toString() { // return name + "[" + originalOpcode + "," + scrampledOpcode + ":" + hasIntConstant + "]"; // } // // } // Path: src/mgi/tools/jagdecs2/instructions/BooleanInstruction.java import mgi.tools.jagdecs2.util.InstructionInfo; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.instructions; public class BooleanInstruction extends AbstractInstruction { private boolean constant;
public BooleanInstruction(InstructionInfo info, boolean constant) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/util/OpcodeUtils.java
// Path: src/mgi/tools/jagdecs2/instructions/Opcodes.java // public class Opcodes { // // public static final int PUSH_INT = 0; // public static final int PUSH_STR = 1; // public static final int PUSH_LONG = 2; // // public static final int LOAD_INT = 3; // public static final int STORE_INT = 4; // public static final int LOAD_STR = 5; // public static final int STORE_STR = 6; // public static final int LOAD_LONG = 7; // public static final int STORE_LONG = 8; // // public static final int POP_INT = 9; // public static final int POP_STR = 10; // public static final int POP_LONG = 11; // // public static final int NEW_ARRAY = 12; // public static final int ARRAY_LOAD = 13; // public static final int ARRAY_STORE = 14; // // public static final int CALL_CS2 = 15; // public static final int RETURN = 16; // // public static final int SWITCH = 17; // public static final int GOTO = 18; // public static final int INT_EQ = 19; // public static final int INT_NE = 20; // public static final int INT_LT = 21; // public static final int INT_GT = 22; // public static final int INT_LE = 23; // public static final int INT_GE = 24; // public static final int INT_T = 25; // public static final int INT_F = 26; // public static final int LONG_EQ = 27; // public static final int LONG_NE = 28; // public static final int LONG_LT = 29; // public static final int LONG_GT = 30; // public static final int LONG_LE = 31; // public static final int LONG_GE = 32; // // public static final int LOAD_CONFIG = 33; // public static final int STORE_CONFIG = 34; // public static final int LOAD_BITCONFIG = 35; // public static final int STORE_BITCONFIG = 36; // public static final int CONCAT_STRINGS = 37; // // // public static int getOpcode(String name) { // try { // Field[] flds = Opcodes.class.getFields(); // for (Field f : flds) { // if (!f.getName().equals(name)) { // continue; // } // return f.getInt(null); // } // } catch (Exception e) { // e.printStackTrace(); // } // return -1; // } // // public static String getOpcodeName(int opcode) { // try { // Field[] flds = Opcodes.class.getFields(); // for (Field f : flds) { // if (f.getInt(null) != opcode) { // continue; // } // return (f.getName()); // } // } catch (Exception e) { // e.printStackTrace(); // } // return "n/a:" + opcode; // } // }
import mgi.tools.jagdecs2.instructions.Opcodes;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.util; public class OpcodeUtils { public static int getTwoConditionsJumpStackType(int opcode) {
// Path: src/mgi/tools/jagdecs2/instructions/Opcodes.java // public class Opcodes { // // public static final int PUSH_INT = 0; // public static final int PUSH_STR = 1; // public static final int PUSH_LONG = 2; // // public static final int LOAD_INT = 3; // public static final int STORE_INT = 4; // public static final int LOAD_STR = 5; // public static final int STORE_STR = 6; // public static final int LOAD_LONG = 7; // public static final int STORE_LONG = 8; // // public static final int POP_INT = 9; // public static final int POP_STR = 10; // public static final int POP_LONG = 11; // // public static final int NEW_ARRAY = 12; // public static final int ARRAY_LOAD = 13; // public static final int ARRAY_STORE = 14; // // public static final int CALL_CS2 = 15; // public static final int RETURN = 16; // // public static final int SWITCH = 17; // public static final int GOTO = 18; // public static final int INT_EQ = 19; // public static final int INT_NE = 20; // public static final int INT_LT = 21; // public static final int INT_GT = 22; // public static final int INT_LE = 23; // public static final int INT_GE = 24; // public static final int INT_T = 25; // public static final int INT_F = 26; // public static final int LONG_EQ = 27; // public static final int LONG_NE = 28; // public static final int LONG_LT = 29; // public static final int LONG_GT = 30; // public static final int LONG_LE = 31; // public static final int LONG_GE = 32; // // public static final int LOAD_CONFIG = 33; // public static final int STORE_CONFIG = 34; // public static final int LOAD_BITCONFIG = 35; // public static final int STORE_BITCONFIG = 36; // public static final int CONCAT_STRINGS = 37; // // // public static int getOpcode(String name) { // try { // Field[] flds = Opcodes.class.getFields(); // for (Field f : flds) { // if (!f.getName().equals(name)) { // continue; // } // return f.getInt(null); // } // } catch (Exception e) { // e.printStackTrace(); // } // return -1; // } // // public static String getOpcodeName(int opcode) { // try { // Field[] flds = Opcodes.class.getFields(); // for (Field f : flds) { // if (f.getInt(null) != opcode) { // continue; // } // return (f.getName()); // } // } catch (Exception e) { // e.printStackTrace(); // } // return "n/a:" + opcode; // } // } // Path: src/mgi/tools/jagdecs2/util/OpcodeUtils.java import mgi.tools.jagdecs2.instructions.Opcodes; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.util; public class OpcodeUtils { public static int getTwoConditionsJumpStackType(int opcode) {
if (opcode >= Opcodes.INT_EQ && opcode <= Opcodes.INT_GE)
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/ast/StringExpressionNode.java
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // }
import mgi.tools.jagdecs2.CS2Type; import mgi.tools.jagdecs2.CodePrinter;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class StringExpressionNode extends ExpressionNode implements IConstantNode { /** * Contains string which this expression holds. */ private String data; public StringExpressionNode(String data) { this.data = data; } public String getData() { return data; } @Override public CS2Type getType() { return CS2Type.STRING; } @Override public Object getConst() { return this.data; } @Override public ExpressionNode copy() { return new StringExpressionNode(this.data); } @Override
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // } // Path: src/mgi/tools/jagdecs2/ast/StringExpressionNode.java import mgi.tools.jagdecs2.CS2Type; import mgi.tools.jagdecs2.CodePrinter; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class StringExpressionNode extends ExpressionNode implements IConstantNode { /** * Contains string which this expression holds. */ private String data; public StringExpressionNode(String data) { this.data = data; } public String getData() { return data; } @Override public CS2Type getType() { return CS2Type.STRING; } @Override public Object getConst() { return this.data; } @Override public ExpressionNode copy() { return new StringExpressionNode(this.data); } @Override
public void print(CodePrinter printer) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/ast/PopableNode.java
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // }
import mgi.tools.jagdecs2.CodePrinter;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class PopableNode extends AbstractCodeNode { private ExpressionNode expression; public PopableNode(ExpressionNode expression) { this.expression = expression; this.write(expression); expression.setParent(this); } public ExpressionNode getExpression() { return expression; } @Override
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // } // Path: src/mgi/tools/jagdecs2/ast/PopableNode.java import mgi.tools.jagdecs2.CodePrinter; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class PopableNode extends AbstractCodeNode { private ExpressionNode expression; public PopableNode(ExpressionNode expression) { this.expression = expression; this.write(expression); expression.setParent(this); } public ExpressionNode getExpression() { return expression; } @Override
public void print(CodePrinter printer) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/ast/CallExpressionNode.java
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // } // // Path: src/mgi/tools/jagdecs2/util/FunctionInfo.java // public class FunctionInfo { // // private String name; // private CS2Type returnType; // private CS2Type[] argumentTypes; // private String[] argumentNames; // // // public FunctionInfo(String name,CS2Type[] argTypes,CS2Type returnType, String[] argNames) { // this.name = name; // this.argumentTypes = argTypes; // this.returnType = returnType; // this.argumentNames = argNames; // } // // // // public String getName() { // return name; // } // // public CS2Type[] getArgumentTypes() { // return argumentTypes; // } // // public CS2Type getReturnType() { // return returnType; // } // // public String[] getArgumentNames() { // return argumentNames; // } // // public String toString() { // StringBuilder bld = new StringBuilder(); // bld.append(returnType); // bld.append(' '); // bld.append(name); // bld.append('('); // for (int i = 0; i < argumentTypes.length; i++) { // bld.append(argumentTypes[i].toString() + " " + argumentNames[i]); // if ((i + 1) < argumentTypes.length) // bld.append(','); // } // bld.append(')'); // bld.append(';'); // return bld.toString(); // } // }
import mgi.tools.jagdecs2.CS2Type; import mgi.tools.jagdecs2.CodePrinter; import mgi.tools.jagdecs2.util.FunctionInfo;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class CallExpressionNode extends ExpressionNode { private FunctionInfo info; private ExpressionNode[] arguments; public CallExpressionNode(FunctionInfo info,ExpressionNode[] arguments) { this.info = info; this.arguments = arguments; for (int i = 0; i < arguments.length; i++) { this.write(arguments[i]); arguments[i].setParent(this); } } @Override public int getPriority() { return ExpressionNode.PRIORITY_CALL; } @Override public CS2Type getType() { return info.getReturnType(); } @Override public ExpressionNode copy() { ExpressionNode[] argsCopy = new ExpressionNode[arguments.length]; for (int i = 0; i < arguments.length; i++) argsCopy[i] = arguments[i].copy(); return new CallExpressionNode(this.info,argsCopy); } @Override
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // } // // Path: src/mgi/tools/jagdecs2/util/FunctionInfo.java // public class FunctionInfo { // // private String name; // private CS2Type returnType; // private CS2Type[] argumentTypes; // private String[] argumentNames; // // // public FunctionInfo(String name,CS2Type[] argTypes,CS2Type returnType, String[] argNames) { // this.name = name; // this.argumentTypes = argTypes; // this.returnType = returnType; // this.argumentNames = argNames; // } // // // // public String getName() { // return name; // } // // public CS2Type[] getArgumentTypes() { // return argumentTypes; // } // // public CS2Type getReturnType() { // return returnType; // } // // public String[] getArgumentNames() { // return argumentNames; // } // // public String toString() { // StringBuilder bld = new StringBuilder(); // bld.append(returnType); // bld.append(' '); // bld.append(name); // bld.append('('); // for (int i = 0; i < argumentTypes.length; i++) { // bld.append(argumentTypes[i].toString() + " " + argumentNames[i]); // if ((i + 1) < argumentTypes.length) // bld.append(','); // } // bld.append(')'); // bld.append(';'); // return bld.toString(); // } // } // Path: src/mgi/tools/jagdecs2/ast/CallExpressionNode.java import mgi.tools.jagdecs2.CS2Type; import mgi.tools.jagdecs2.CodePrinter; import mgi.tools.jagdecs2.util.FunctionInfo; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class CallExpressionNode extends ExpressionNode { private FunctionInfo info; private ExpressionNode[] arguments; public CallExpressionNode(FunctionInfo info,ExpressionNode[] arguments) { this.info = info; this.arguments = arguments; for (int i = 0; i < arguments.length; i++) { this.write(arguments[i]); arguments[i].setParent(this); } } @Override public int getPriority() { return ExpressionNode.PRIORITY_CALL; } @Override public CS2Type getType() { return info.getReturnType(); } @Override public ExpressionNode copy() { ExpressionNode[] argsCopy = new ExpressionNode[arguments.length]; for (int i = 0; i < arguments.length; i++) argsCopy[i] = arguments[i].copy(); return new CallExpressionNode(this.info,argsCopy); } @Override
public void print(CodePrinter printer) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/ast/VariableLoadNode.java
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // }
import mgi.tools.jagdecs2.CS2Type; import mgi.tools.jagdecs2.CodePrinter;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class VariableLoadNode extends ExpressionNode { private LocalVariable variable; public VariableLoadNode(LocalVariable variable) { this.variable = variable; } @Override public CS2Type getType() { return this.variable.getType(); } @Override public ExpressionNode copy() { return new VariableLoadNode(this.variable); } public LocalVariable getVariable() { return variable; } public void setVariable(LocalVariable v) { this.variable = v; } @Override
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // } // Path: src/mgi/tools/jagdecs2/ast/VariableLoadNode.java import mgi.tools.jagdecs2.CS2Type; import mgi.tools.jagdecs2.CodePrinter; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class VariableLoadNode extends ExpressionNode { private LocalVariable variable; public VariableLoadNode(LocalVariable variable) { this.variable = variable; } @Override public CS2Type getType() { return this.variable.getType(); } @Override public ExpressionNode copy() { return new VariableLoadNode(this.variable); } public LocalVariable getVariable() { return variable; } public void setVariable(LocalVariable v) { this.variable = v; } @Override
public void print(CodePrinter printer) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/ast/ArrayLoadNode.java
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // }
import mgi.tools.jagdecs2.CS2Type; import mgi.tools.jagdecs2.CodePrinter;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class ArrayLoadNode extends ExpressionNode { private ExpressionNode array; private ExpressionNode index; public ArrayLoadNode(ExpressionNode array,ExpressionNode index) { this.array = array; this.index = index; this.write(array); this.write(index); array.setParent(this); index.setParent(this); } @Override public int getPriority() { return ExpressionNode.PRIORITY_ARRAY_INDEX; } @Override public CS2Type getType() { return array.getType().getElementType(); } @Override public ExpressionNode copy() { return new ArrayLoadNode(this.array.copy(), this.index.copy()); } @Override
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // } // Path: src/mgi/tools/jagdecs2/ast/ArrayLoadNode.java import mgi.tools.jagdecs2.CS2Type; import mgi.tools.jagdecs2.CodePrinter; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class ArrayLoadNode extends ExpressionNode { private ExpressionNode array; private ExpressionNode index; public ArrayLoadNode(ExpressionNode array,ExpressionNode index) { this.array = array; this.index = index; this.write(array); this.write(index); array.setParent(this); index.setParent(this); } @Override public int getPriority() { return ExpressionNode.PRIORITY_ARRAY_INDEX; } @Override public CS2Type getType() { return array.getType().getElementType(); } @Override public ExpressionNode copy() { return new ArrayLoadNode(this.array.copy(), this.index.copy()); } @Override
public void print(CodePrinter printer) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/ast/NotExpressionNode.java
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // }
import mgi.tools.jagdecs2.CS2Type; import mgi.tools.jagdecs2.CodePrinter;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class NotExpressionNode extends ExpressionNode { /** * Contains left expression node. */ private ExpressionNode expression; public NotExpressionNode(ExpressionNode expression) { this.expression = expression; this.write(expression); this.expression.setParent(this); } @Override public int getPriority() { return ExpressionNode.PRIORITY_UNARYLOGICALNOT; } @Override public CS2Type getType() { return CS2Type.BOOLEAN; } @Override
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // } // Path: src/mgi/tools/jagdecs2/ast/NotExpressionNode.java import mgi.tools.jagdecs2.CS2Type; import mgi.tools.jagdecs2.CodePrinter; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class NotExpressionNode extends ExpressionNode { /** * Contains left expression node. */ private ExpressionNode expression; public NotExpressionNode(ExpressionNode expression) { this.expression = expression; this.write(expression); this.expression.setParent(this); } @Override public int getPriority() { return ExpressionNode.PRIORITY_UNARYLOGICALNOT; } @Override public CS2Type getType() { return CS2Type.BOOLEAN; } @Override
public void print(CodePrinter printer) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/ast/ConditionalExpressionNode.java
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // }
import mgi.tools.jagdecs2.CS2Type; import mgi.tools.jagdecs2.CodePrinter;
@Override public CS2Type getType() { return CS2Type.BOOLEAN; } private String conditionalToString() { switch (this.conditional) { case 0: return "!="; case 1: return "=="; case 2: return ">"; case 3: return "<"; case 4: return ">="; case 5: return "<="; case 6: return "||"; case 7: return "&&"; default: return "??"; } } @Override
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // } // Path: src/mgi/tools/jagdecs2/ast/ConditionalExpressionNode.java import mgi.tools.jagdecs2.CS2Type; import mgi.tools.jagdecs2.CodePrinter; @Override public CS2Type getType() { return CS2Type.BOOLEAN; } private String conditionalToString() { switch (this.conditional) { case 0: return "!="; case 1: return "=="; case 2: return ">"; case 3: return "<"; case 4: return ">="; case 5: return "<="; case 6: return "||"; case 7: return "&&"; default: return "??"; } } @Override
public void print(CodePrinter printer) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/ast/UnconditionalFlowBlockJump.java
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // }
import mgi.tools.jagdecs2.CodePrinter;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class UnconditionalFlowBlockJump extends AbstractCodeNode { /** * Contains target flow block. */ private FlowBlock target; public UnconditionalFlowBlockJump(FlowBlock target) { this.target = target; } public FlowBlock getTarget() { return target; } @Override
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // } // Path: src/mgi/tools/jagdecs2/ast/UnconditionalFlowBlockJump.java import mgi.tools.jagdecs2.CodePrinter; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class UnconditionalFlowBlockJump extends AbstractCodeNode { /** * Contains target flow block. */ private FlowBlock target; public UnconditionalFlowBlockJump(FlowBlock target) { this.target = target; } public FlowBlock getTarget() { return target; } @Override
public void print(CodePrinter printer) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/gui/OptionsPanel.java
// Path: src/mgi/tools/jagdecs2/util/Options.java // public class Options { // // private File file; // private HashMap<String, String> options; // // public Options(File file) { // this.file = file; // this.options = new HashMap<String, String>(); // reload(); // } // // /** // * Save's options to file. // */ // public void save() { // try { // BufferedWriter writer = new BufferedWriter(new FileWriter(file)); // // writer.write("# Auto generated options - DO NOT EDIT\n\n\n\n"); // // for (String key : options.keySet()) { // writer.write(key + " " + options.get(key) + "\n\n"); // } // // writer.close(); // } // catch (Throwable t) { // t.printStackTrace(); // } // } // // /** // * Read's options from options file. // */ // public void reload() { // try { // BufferedReader reader = new BufferedReader(new FileReader(file)); // // int linesCount = 0; // for (String line = reader.readLine(); line != null; line = reader.readLine(), linesCount++) { // if (line.length() <= 0 || line.startsWith(" ") || line.startsWith("//") || line.startsWith("#")) // continue; // try { // int space = line.indexOf(' '); // if (space <= 0) { // reader.close(); // throw new RuntimeException("Bad syntax!"); // } // String key = line.substring(0, space); // String value = line.substring(space + 1); // setOption(key, value); // } // catch (Exception ex) { // reader.close(); // throw new RuntimeException("Error parsing options file " + file + " on line:" + (linesCount + 1)); // } // } // // reader.close(); // } // catch (Throwable t) { // t.printStackTrace(); // } // } // // /** // * Get's option. // * Return's null if it's not found. // */ // public String getOption(String key) { // if (options.containsKey(key)) // return options.get(key); // return null; // } // // /** // * Set's option. // */ // public void setOption(String key, String value) { // if (options.containsKey(key)) // options.remove(key); // options.put(key, value); // } // // // // }
import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.JLabel; import javax.swing.JButton; import mgi.tools.jagdecs2.util.Options; import com.jgoodies.forms.layout.FormLayout; import com.jgoodies.forms.layout.ColumnSpec; import com.jgoodies.forms.layout.RowSpec; import com.jgoodies.forms.factories.FormFactory; import java.awt.Font; import java.awt.event.ActionListener; import java.awt.event.ActionEvent;
opcPath.setText("Loading please wait..."); opcPath.setColumns(10); opcPath.setBounds(43, 89, 184, 20); add(opcPath); JLabel lblScr = new JLabel("Scripts database path:"); lblScr.setFont(new Font("Tahoma", Font.BOLD, 13)); lblScr.setBounds(43, 135, 184, 14); add(lblScr); scrPath = new JTextField(); scrPath.setText("Loading please wait..."); scrPath.setColumns(10); scrPath.setBounds(43, 155, 184, 20); add(scrPath); JLabel lblScrs = new JLabel("Scripts path:"); lblScrs.setFont(new Font("Tahoma", Font.BOLD, 13)); lblScrs.setBounds(256, 11, 184, 14); add(lblScrs); scrsPath = new JTextField(); scrsPath.setText("Loading please wait..."); scrsPath.setColumns(10); scrsPath.setBounds(256, 31, 184, 20); add(scrsPath); JButton btnApply = new JButton("Apply"); btnApply.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
// Path: src/mgi/tools/jagdecs2/util/Options.java // public class Options { // // private File file; // private HashMap<String, String> options; // // public Options(File file) { // this.file = file; // this.options = new HashMap<String, String>(); // reload(); // } // // /** // * Save's options to file. // */ // public void save() { // try { // BufferedWriter writer = new BufferedWriter(new FileWriter(file)); // // writer.write("# Auto generated options - DO NOT EDIT\n\n\n\n"); // // for (String key : options.keySet()) { // writer.write(key + " " + options.get(key) + "\n\n"); // } // // writer.close(); // } // catch (Throwable t) { // t.printStackTrace(); // } // } // // /** // * Read's options from options file. // */ // public void reload() { // try { // BufferedReader reader = new BufferedReader(new FileReader(file)); // // int linesCount = 0; // for (String line = reader.readLine(); line != null; line = reader.readLine(), linesCount++) { // if (line.length() <= 0 || line.startsWith(" ") || line.startsWith("//") || line.startsWith("#")) // continue; // try { // int space = line.indexOf(' '); // if (space <= 0) { // reader.close(); // throw new RuntimeException("Bad syntax!"); // } // String key = line.substring(0, space); // String value = line.substring(space + 1); // setOption(key, value); // } // catch (Exception ex) { // reader.close(); // throw new RuntimeException("Error parsing options file " + file + " on line:" + (linesCount + 1)); // } // } // // reader.close(); // } // catch (Throwable t) { // t.printStackTrace(); // } // } // // /** // * Get's option. // * Return's null if it's not found. // */ // public String getOption(String key) { // if (options.containsKey(key)) // return options.get(key); // return null; // } // // /** // * Set's option. // */ // public void setOption(String key, String value) { // if (options.containsKey(key)) // options.remove(key); // options.put(key, value); // } // // // // } // Path: src/mgi/tools/jagdecs2/gui/OptionsPanel.java import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.JLabel; import javax.swing.JButton; import mgi.tools.jagdecs2.util.Options; import com.jgoodies.forms.layout.FormLayout; import com.jgoodies.forms.layout.ColumnSpec; import com.jgoodies.forms.layout.RowSpec; import com.jgoodies.forms.factories.FormFactory; import java.awt.Font; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; opcPath.setText("Loading please wait..."); opcPath.setColumns(10); opcPath.setBounds(43, 89, 184, 20); add(opcPath); JLabel lblScr = new JLabel("Scripts database path:"); lblScr.setFont(new Font("Tahoma", Font.BOLD, 13)); lblScr.setBounds(43, 135, 184, 14); add(lblScr); scrPath = new JTextField(); scrPath.setText("Loading please wait..."); scrPath.setColumns(10); scrPath.setBounds(43, 155, 184, 20); add(scrPath); JLabel lblScrs = new JLabel("Scripts path:"); lblScrs.setFont(new Font("Tahoma", Font.BOLD, 13)); lblScrs.setBounds(256, 11, 184, 14); add(lblScrs); scrsPath = new JTextField(); scrsPath.setText("Loading please wait..."); scrsPath.setColumns(10); scrsPath.setBounds(256, 31, 184, 20); add(scrsPath); JButton btnApply = new JButton("Apply"); btnApply.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
Options options = window.getMain().getOptions();
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/ast/ContinueNode.java
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // }
import mgi.tools.jagdecs2.CodePrinter;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class ContinueNode extends AbstractCodeNode implements IFlowControlNode { private IContinueableNode node; private ScopeNode selfScope; public ContinueNode(ScopeNode selfScope, IContinueableNode node) { this.node = node; this.selfScope = selfScope; // don't need to write self scope because it's just for label checks. (Not expressed). if (this.getSelfScope().getParent() != node && node.getLabelName() == null) node.enableLabelName(); } @Override public IContinueableNode getNode() { return node; } public ScopeNode getSelfScope() { return selfScope; } @Override
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // } // Path: src/mgi/tools/jagdecs2/ast/ContinueNode.java import mgi.tools.jagdecs2.CodePrinter; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class ContinueNode extends AbstractCodeNode implements IFlowControlNode { private IContinueableNode node; private ScopeNode selfScope; public ContinueNode(ScopeNode selfScope, IContinueableNode node) { this.node = node; this.selfScope = selfScope; // don't need to write self scope because it's just for label checks. (Not expressed). if (this.getSelfScope().getParent() != node && node.getLabelName() == null) node.enableLabelName(); } @Override public IContinueableNode getNode() { return node; } public ScopeNode getSelfScope() { return selfScope; } @Override
public void print(CodePrinter printer) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/ast/BuildStringNode.java
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // }
import mgi.tools.jagdecs2.CS2Type; import mgi.tools.jagdecs2.CodePrinter;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class BuildStringNode extends ExpressionNode { private ExpressionNode[] arguments; public BuildStringNode(ExpressionNode[] arguments) { this.arguments = arguments; for (int i = 0; i < arguments.length; i++) { this.write(arguments[i]); arguments[i].setParent(this); } } @Override public int getPriority() { return ExpressionNode.PRIORITY_CONTACTSTRING; } @Override public CS2Type getType() { return CS2Type.STRING; } @Override public ExpressionNode copy() { ExpressionNode[] argsCopy = new ExpressionNode[arguments.length]; for (int i = 0; i < arguments.length; i++) argsCopy[i] = arguments[i].copy(); return new BuildStringNode(argsCopy); } @Override
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // } // Path: src/mgi/tools/jagdecs2/ast/BuildStringNode.java import mgi.tools.jagdecs2.CS2Type; import mgi.tools.jagdecs2.CodePrinter; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class BuildStringNode extends ExpressionNode { private ExpressionNode[] arguments; public BuildStringNode(ExpressionNode[] arguments) { this.arguments = arguments; for (int i = 0; i < arguments.length; i++) { this.write(arguments[i]); arguments[i].setParent(this); } } @Override public int getPriority() { return ExpressionNode.PRIORITY_CONTACTSTRING; } @Override public CS2Type getType() { return CS2Type.STRING; } @Override public ExpressionNode copy() { ExpressionNode[] argsCopy = new ExpressionNode[arguments.length]; for (int i = 0; i < arguments.length; i++) argsCopy[i] = arguments[i].copy(); return new BuildStringNode(argsCopy); } @Override
public void print(CodePrinter printer) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/ast/AbstractCodeNode.java
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // }
import java.util.ArrayList; import java.util.List; import mgi.tools.jagdecs2.CodePrinter;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public abstract class AbstractCodeNode { private static final int INITIAL_BUFFER_SIZE = 4; private AbstractCodeNode[] childs; private int codeAddress;
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // } // Path: src/mgi/tools/jagdecs2/ast/AbstractCodeNode.java import java.util.ArrayList; import java.util.List; import mgi.tools.jagdecs2.CodePrinter; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public abstract class AbstractCodeNode { private static final int INITIAL_BUFFER_SIZE = 4; private AbstractCodeNode[] childs; private int codeAddress;
public abstract void print(CodePrinter printer);
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/instructions/LongInstruction.java
// Path: src/mgi/tools/jagdecs2/util/InstructionInfo.java // public class InstructionInfo { // // private String name; // private int scrampledOpcode; // private int originalOpcode; // private boolean hasIntConstant; // // public InstructionInfo(String name, int scrampledop, int originalop, boolean hasIntConstant) { // this.name = name; // this.scrampledOpcode = scrampledop; // this.originalOpcode = originalop; // this.hasIntConstant = hasIntConstant; // } // // public String getName() { // return name; // } // // public int getScrampledOpcode() { // return scrampledOpcode; // } // // public int getOpcode() { // return originalOpcode; // } // // public boolean hasIntConstant() { // return hasIntConstant; // } // // @Override // public String toString() { // return name + "[" + originalOpcode + "," + scrampledOpcode + ":" + hasIntConstant + "]"; // } // // }
import mgi.tools.jagdecs2.util.InstructionInfo;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.instructions; public class LongInstruction extends AbstractInstruction { private long constant;
// Path: src/mgi/tools/jagdecs2/util/InstructionInfo.java // public class InstructionInfo { // // private String name; // private int scrampledOpcode; // private int originalOpcode; // private boolean hasIntConstant; // // public InstructionInfo(String name, int scrampledop, int originalop, boolean hasIntConstant) { // this.name = name; // this.scrampledOpcode = scrampledop; // this.originalOpcode = originalop; // this.hasIntConstant = hasIntConstant; // } // // public String getName() { // return name; // } // // public int getScrampledOpcode() { // return scrampledOpcode; // } // // public int getOpcode() { // return originalOpcode; // } // // public boolean hasIntConstant() { // return hasIntConstant; // } // // @Override // public String toString() { // return name + "[" + originalOpcode + "," + scrampledOpcode + ":" + hasIntConstant + "]"; // } // // } // Path: src/mgi/tools/jagdecs2/instructions/LongInstruction.java import mgi.tools.jagdecs2.util.InstructionInfo; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.instructions; public class LongInstruction extends AbstractInstruction { private long constant;
public LongInstruction(InstructionInfo info, long constant) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/instructions/ConfigInstruction.java
// Path: src/mgi/tools/jagdecs2/util/ConfigInfo.java // public class ConfigInfo { // // private String domainName; // private String configName; // private CS2Type type; // // public ConfigInfo(String domainName, String configName, CS2Type type) { // this.domainName = domainName; // this.configName = configName; // this.type = type; // } // // public String getDomainName() { // return domainName; // } // // public String getConfigName() { // return configName; // } // // public CS2Type getType() { // return type; // } // // @Override // public String toString() { // return "[" + domainName + "," + configName + "," + type + "]"; // } // // } // // Path: src/mgi/tools/jagdecs2/util/InstructionInfo.java // public class InstructionInfo { // // private String name; // private int scrampledOpcode; // private int originalOpcode; // private boolean hasIntConstant; // // public InstructionInfo(String name, int scrampledop, int originalop, boolean hasIntConstant) { // this.name = name; // this.scrampledOpcode = scrampledop; // this.originalOpcode = originalop; // this.hasIntConstant = hasIntConstant; // } // // public String getName() { // return name; // } // // public int getScrampledOpcode() { // return scrampledOpcode; // } // // public int getOpcode() { // return originalOpcode; // } // // public boolean hasIntConstant() { // return hasIntConstant; // } // // @Override // public String toString() { // return name + "[" + originalOpcode + "," + scrampledOpcode + ":" + hasIntConstant + "]"; // } // // }
import mgi.tools.jagdecs2.util.ConfigInfo; import mgi.tools.jagdecs2.util.InstructionInfo;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.instructions; public class ConfigInstruction extends AbstractInstruction { private ConfigInfo config; private boolean constant;
// Path: src/mgi/tools/jagdecs2/util/ConfigInfo.java // public class ConfigInfo { // // private String domainName; // private String configName; // private CS2Type type; // // public ConfigInfo(String domainName, String configName, CS2Type type) { // this.domainName = domainName; // this.configName = configName; // this.type = type; // } // // public String getDomainName() { // return domainName; // } // // public String getConfigName() { // return configName; // } // // public CS2Type getType() { // return type; // } // // @Override // public String toString() { // return "[" + domainName + "," + configName + "," + type + "]"; // } // // } // // Path: src/mgi/tools/jagdecs2/util/InstructionInfo.java // public class InstructionInfo { // // private String name; // private int scrampledOpcode; // private int originalOpcode; // private boolean hasIntConstant; // // public InstructionInfo(String name, int scrampledop, int originalop, boolean hasIntConstant) { // this.name = name; // this.scrampledOpcode = scrampledop; // this.originalOpcode = originalop; // this.hasIntConstant = hasIntConstant; // } // // public String getName() { // return name; // } // // public int getScrampledOpcode() { // return scrampledOpcode; // } // // public int getOpcode() { // return originalOpcode; // } // // public boolean hasIntConstant() { // return hasIntConstant; // } // // @Override // public String toString() { // return name + "[" + originalOpcode + "," + scrampledOpcode + ":" + hasIntConstant + "]"; // } // // } // Path: src/mgi/tools/jagdecs2/instructions/ConfigInstruction.java import mgi.tools.jagdecs2.util.ConfigInfo; import mgi.tools.jagdecs2.util.InstructionInfo; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.instructions; public class ConfigInstruction extends AbstractInstruction { private ConfigInfo config; private boolean constant;
public ConfigInstruction(InstructionInfo info, ConfigInfo config, boolean constant) {
Someone52/CS2-Decompiler
src/mgi/tools/jagdecs2/ast/StoreNamedDataNode.java
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // }
import mgi.tools.jagdecs2.CS2Type; import mgi.tools.jagdecs2.CodePrinter;
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class StoreNamedDataNode extends ExpressionNode { private String name; private ExpressionNode expression; public StoreNamedDataNode(String name,ExpressionNode expr) { this.name = name; this.expression = expr; this.write(expr); expr.setParent(this); } @Override public int getPriority() { return ExpressionNode.PRIORITY_ASSIGNMENT; } @Override public CS2Type getType() { return this.expression.getType(); } @Override public ExpressionNode copy() { return new StoreNamedDataNode(this.name, this.expression.copy()); } public String getName() { return name; } public ExpressionNode getExpression() { return expression; } @Override
// Path: src/mgi/tools/jagdecs2/CodePrinter.java // public class CodePrinter { // // protected StringWriter writer; // private int tabs; // // // public CodePrinter() { // writer = new StringWriter(); // tabs = 0; // } // // /** // * Method , unused by default that notifies that specific node is // * about to be printed. // */ // public void beginPrinting(AbstractCodeNode node) { } // // /** // * Method, unused by default that notifies that specific node was // * printed. // */ // public void endPrinting(AbstractCodeNode node) { } // // // public void print(CharSequence str) { // for (int i = 0; i < str.length(); i++) // print(str.charAt(i)); // } // // public void print(char c) { // writer.append(c); // if (c == '\n') // writer.append(getTabs()); // } // // protected String getTabs() { // StringBuilder tabs = new StringBuilder(); // for (int i = 0; i < this.tabs; i++) // tabs.append('\t'); // return tabs.toString(); // } // // public void tab() { // tabs++; // } // // public void untab() { // if (tabs <= 0) // throw new RuntimeException("Not tabbed!"); // tabs--; // } // // @Override // public String toString() { // writer.flush(); // return writer.toString(); // } // // public static String print(AbstractCodeNode node) { // CodePrinter printer = new CodePrinter(); // node.print(printer); // return printer.toString(); // } // // } // Path: src/mgi/tools/jagdecs2/ast/StoreNamedDataNode.java import mgi.tools.jagdecs2.CS2Type; import mgi.tools.jagdecs2.CodePrinter; /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mgi.tools.jagdecs2.ast; public class StoreNamedDataNode extends ExpressionNode { private String name; private ExpressionNode expression; public StoreNamedDataNode(String name,ExpressionNode expr) { this.name = name; this.expression = expr; this.write(expr); expr.setParent(this); } @Override public int getPriority() { return ExpressionNode.PRIORITY_ASSIGNMENT; } @Override public CS2Type getType() { return this.expression.getType(); } @Override public ExpressionNode copy() { return new StoreNamedDataNode(this.name, this.expression.copy()); } public String getName() { return name; } public ExpressionNode getExpression() { return expression; } @Override
public void print(CodePrinter printer) {