private static void writeTrace( final Trace trace, final int traceId, final JsonGenerator generator) throws IOException { generator.writeStartObject(); generator.writeNumberField(JsonTraceCodec.TRACE_ID, traceId); generator.writeStringField(JsonTraceCodec.TRACE_NAME, trace.getName()); generator.writeStringField(JsonTraceCodec.TRACE_RESULT_TYPE, trace.getResultType().toString()); generator.writeBooleanField(JsonTraceCodec.TRACE_HIDDEN, trace.getHidden()); generator.writeBooleanField(JsonTraceCodec.TRACE_SYSTEM_HIDDEN, trace.getSystemHidden()); if (trace.getValue() != null) { generator.writeStringField(JsonTraceCodec.TRACE_VALUE, trace.getValue()); } if (trace.getStartNanos() != null) { generator.writeNumberField(JsonTraceCodec.TRACE_START_NANOS, trace.getStartNanos()); } if (trace.getEndNanos() != null) { generator.writeNumberField(JsonTraceCodec.TRACE_END_NANOS, trace.getEndNanos()); } if (trace.getAttributes() != null && trace.getAttributes().size() > 0) { generator.writeArrayFieldStart(JsonTraceCodec.TRACE_ATTRIBUTES); for (Map.Entry<String, String> attribute : trace.getAttributes().entrySet()) { generator.writeStartObject(); generator.writeStringField(JsonTraceCodec.TRACE_ATTRIBUTE_KEY, attribute.getKey()); generator.writeStringField(JsonTraceCodec.TRACE_ATTRIBUTE_VALUE, attribute.getValue()); generator.writeEndObject(); } generator.writeEndArray(); } generator.writeEndObject(); }
public void toJson(JsonGenerator gen) throws IOException { gen.writeStartObject(); if (type != null) { gen.writeStringField("type", type.getName()); } if (tableName != null) { gen.writeStringField("tableName", tableName); } if (versionUpdated != -1) { gen.writeNumberField("versionUpdated", versionUpdated); } if (versionCreated != -1) { gen.writeNumberField("versionCreated", versionCreated); } if (recordTypeChanged) { gen.writeBooleanField("recordTypeChanged", true); } if (updatedFields != null && updatedFields.size() > 0) { gen.writeArrayFieldStart("updatedFields"); for (SchemaId updatedField : updatedFields) { gen.writeBinary(updatedField.getBytes()); } gen.writeEndArray(); } if (vtagsToIndex != null && vtagsToIndex.size() > 0) { gen.writeArrayFieldStart("vtagsToIndex"); for (SchemaId vtag : vtagsToIndex) { gen.writeBinary(vtag.getBytes()); } gen.writeEndArray(); } if (attributes != null && attributes.size() > 0) { gen.writeObjectFieldStart("attributes"); for (String key : attributes.keySet()) { gen.writeStringField(key, attributes.get(key)); } gen.writeEndObject(); } if (indexRecordFilterData != null) { gen.writeFieldName("indexFilterData"); indexRecordFilterData.toJson(gen); } gen.writeEndObject(); gen.flush(); }
public static void writeSignal( String name, int bottom, int top, int integer, int fractional, JsonGenerator g) throws JsonGenerationException, IOException { g.writeStartObject(); g.writeStringField("name", name); g.writeNumberField("bottom", bottom); g.writeNumberField("top", top); g.writeNumberField("integer", integer); g.writeNumberField("fractional", fractional); g.writeEndObject(); }
private void write(JsonGenerator jg, TwitterEntry entry) throws IOException { jg.writeStartObject(); // can either do "jg.writeFieldName(...) + jg.writeNumber()", or this: jg.writeNumberField("id", entry.getId()); jg.writeStringField("text", entry.getText()); jg.writeNumberField("fromUserId", entry.getFromUserId()); jg.writeNumberField("toUserId", entry.getToUserId()); jg.writeStringField("langugeCode", entry.getLanguageCode()); jg.writeEndObject(); jg.close(); }
public void dump(OutputStream os, BaseResponse res) { D2ResponseMessage d2Response = (D2ResponseMessage) res; try { OutputStreamWriter writer; writer = new OutputStreamWriter(os, charset); JsonGenerator generator = objectMapper.getJsonFactory().createJsonGenerator(writer); if (pretty) { JsonPrettyPrinter pp = new JsonPrettyPrinter(); generator.setPrettyPrinter(pp); } // generator.writeStartArray(); { List<D2ResponseMessageDoc> list = d2Response.getDocs(); for (D2ResponseMessageDoc doc : list) { generator.writeStartObject(); { generator.writeStringField("md5Lite", Md5Lite.toString(doc.getMd5Lite())); generator.writeNumberField("weight", doc.getWeight()); generator.writeNumberField("indentValue", doc.getIndentValue()); generator.writeNumberField("indentCount", doc.getIndentCount()); generator.writeNumberField("indentPage", doc.getIndentPage()); generator.writeNumberField("po", doc.getPo()); generator.writeNumberField("ph", doc.getPh()); } generator.writeEndObject(); } } generator.writeEndArray(); // generator.flush(); writer.flush(); } catch (UnsupportedEncodingException e) { logger.error("dump response failed.", e); } catch (IOException e) { logger.error("dump response failed.", e); } finally { } }
private void writeCollect(SelectSet selectSet) throws IOException { writer.writeFieldName("collect"); writer.writeStartObject(); writer.writeNumberField("limit", selectSet.getLimit()); writeDynamicData(selectSet.getData()); writer.writeEndObject(); }
private Response.Status optInResource(String resourceId, boolean optIn, JsonGenerator gen) throws IOException { String op = optIn ? "in" : "out"; LOGGER.info(String.format("Opt %s resource %s for Janitor Monkey.", op, resourceId)); Response.Status responseStatus; Event evt; if (optIn) { evt = monkey.optInResource(resourceId); } else { evt = monkey.optOutResource(resourceId); } if (evt != null) { responseStatus = Response.Status.OK; gen.writeStringField("monkeyType", evt.monkeyType().name()); gen.writeStringField("eventId", evt.id()); gen.writeNumberField("eventTime", evt.eventTime().getTime()); gen.writeStringField("region", evt.region()); for (Map.Entry<String, String> pair : evt.fields().entrySet()) { gen.writeStringField(pair.getKey(), pair.getValue()); } } else { responseStatus = Response.Status.INTERNAL_SERVER_ERROR; gen.writeStringField( "message", String.format("Failed to opt %s resource %s", op, resourceId)); } LOGGER.info(String.format("Opt %s operation completed.", op)); return responseStatus; }
@Override public void serialize( SimpleEvaluationObject value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { synchronized (value) { String id = getUpdateManager().register(value); jgen.writeStartObject(); jgen.writeObjectField("type", "SimpleEvaluationObject"); jgen.writeStringField("update_id", id); jgen.writeStringField("expression", value.getExpression()); jgen.writeObjectField("status", value.getStatus()); if (value.getMessage() != null) jgen.writeStringField("message", value.getMessage()); if (value.getProgressBar() > 0) jgen.writeNumberField("progressBar", value.getProgressBar()); if (value.getPayloadChanged()) { EvaluationResult o = value.getPayload(); if (o != null && o.getValue() != null) { jgen.writeFieldName("payload"); if (!getObjectSerializer().writeObject(o, jgen, true)) jgen.writeObject(o.toString()); } else if (value.getJsonRes() != null) { jgen.writeFieldName("payload"); if (ControlCharacterUtils.containsControlCharacters(value.getJsonRes())) { jgen.writeRawValue(ControlCharacterUtils.escapeControlCharacters(value.getJsonRes())); } else { jgen.writeRawValue(value.getJsonRes()); } } } if (value.getJsonRes() != null && value.getPayload() != null && value.getPayload().getValue() != null) { logger.trace("adding raw json data: '" + value.getJsonRes() + "'"); jgen.writeFieldName("jsonres"); if (ControlCharacterUtils.containsControlCharacters(value.getJsonRes())) { jgen.writeRawValue(ControlCharacterUtils.escapeControlCharacters(value.getJsonRes())); } else { jgen.writeRawValue(value.getJsonRes()); } } jgen.writeArrayFieldStart("outputdata"); for (Object o : value.getOutputdata()) { if (o instanceof EvaluationStdOutput) { jgen.writeStartObject(); jgen.writeStringField("type", "out"); jgen.writeStringField("value", ((EvaluationStdOutput) o).payload); jgen.writeEndObject(); } else if (o instanceof EvaluationStdError) { jgen.writeStartObject(); jgen.writeStringField("type", "err"); jgen.writeStringField("value", ((EvaluationStdError) o).payload); jgen.writeEndObject(); } } jgen.writeEndArray(); jgen.writeEndObject(); } }
private static void writeRelationships( final Map<Trace, Integer> traceIds, final JsonGenerator generator) throws IOException { generator.writeArrayFieldStart(JsonTraceCodec.RELATIONSHIPS); for (Map.Entry<Trace, Integer> entry : traceIds.entrySet()) { final Trace trace = entry.getKey(); final int fromId = entry.getValue(); for (Related<Trace> related : trace.getRelated()) { final int toId = traceIds.get(related.getRelated()); final String relationship = related.getRelationship(); generator.writeStartObject(); generator.writeStringField(JsonTraceCodec.RELATIONSHIP_RELATIONSHIP, relationship); generator.writeNumberField(JsonTraceCodec.RELATIONSHIP_FROM, fromId); generator.writeNumberField(JsonTraceCodec.RELATIONSHIP_TO, toId); generator.writeEndObject(); } } generator.writeEndArray(); }
protected void writeExtendedInfo(JsonGenerator jg, String key, Serializable value) throws IOException { Class<?> clazz = value.getClass(); if (Long.class.isAssignableFrom(clazz)) { jg.writeNumberField(key, (Long) value); } else if (Integer.class.isAssignableFrom(clazz)) { jg.writeNumberField(key, (Integer) value); } else if (Double.class.isAssignableFrom(clazz)) { jg.writeNumberField(key, (Double) value); } else if (Date.class.isAssignableFrom(clazz)) { jg.writeStringField(key, ISODateTimeFormat.dateTime().print(new DateTime(value))); } else if (String.class.isAssignableFrom(clazz)) { jg.writeStringField(key, (String) value); } else if (Boolean.class.isAssignableFrom(clazz)) { jg.writeBooleanField(key, (Boolean) value); } else { jg.writeStringField(key, value.toString()); } }
@Override public void writeTo( Object object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { JsonGenerator writer = null; if (type.isAssignableFrom(ArtifactReadable.class)) { ArtifactReadable artifact = (ArtifactReadable) object; try { writer = jsonFactory.createJsonGenerator(entityStream); // writer.setPrettyPrinter(new DefaultPr) writer.writeStartObject(); writer.writeNumberField("uuid", artifact.getLocalId()); if (matches(IdentityView.class, annotations)) { writer.writeStringField("Name", artifact.getName()); } else { AttributeTypes attributeTypes = getAttibuteTypes(); Collection<? extends IAttributeType> attrTypes = attributeTypes.getAll(); ResultSet<? extends AttributeReadable<Object>> attributes = artifact.getAttributes(); if (!attributes.isEmpty()) { for (IAttributeType attrType : attrTypes) { if (artifact.isAttributeTypeValid(attrType)) { List<Object> attributeValues = artifact.getAttributeValues(attrType); if (!attributeValues.isEmpty()) { if (attributeValues.size() > 1) { writer.writeArrayFieldStart(attrType.getName()); for (Object value : attributeValues) { writer.writeObject(value); } writer.writeEndArray(); } else if (attributeValues.size() == 1) { Object value = attributeValues.iterator().next(); writer.writeObjectField(attrType.getName(), value); } } } } } } writer.writeEndObject(); } finally { if (writer != null) { writer.flush(); } } } }
@Override public void serialize(Producto producto, JsonGenerator jsonGenerator, SerializerProvider sp) throws IOException, org.codehaus.jackson.JsonProcessingException { jsonGenerator.writeStartObject(); jsonGenerator.writeNumberField("idproducto", producto.getIdproducto()); jsonGenerator.writeStringField("nombre", producto.getNombreProducto()); if (producto.getImagen() != null) { jsonGenerator.writeBinaryField("imagen", producto.getImagen()); } jsonGenerator.writeStringField( "categoria", producto.getCategoriaIdCategoria().getNombreCategoria()); jsonGenerator.writeEndObject(); }
private void writeQuery(QueryData queryData) throws IOException { List<CriteriaSet> criteriaSets = queryData.getCriteriaSets(); List<SelectSet> selectSets = queryData.getSelectSets(); writer.writeArrayFieldStart("query"); for (int index = 0; index < criteriaSets.size(); index++) { writer.writeStartObject(); writer.writeNumberField("level", index); writeCriterias(criteriaSets.get(index)); writeCollect(selectSets.get(index)); writer.writeEndObject(); } writer.writeEndArray(); }
@Override protected void writeEntityBody(JsonGenerator jg, LogEntry logEntry) throws IOException { jg.writeStringField("entity-type", "logEntry"); jg.writeStringField("category", logEntry.getCategory()); jg.writeStringField("principalName", logEntry.getPrincipalName()); jg.writeStringField("comment", logEntry.getComment()); jg.writeStringField("docLifeCycle", logEntry.getDocLifeCycle()); jg.writeStringField("docPath", logEntry.getDocPath()); jg.writeStringField("docType", logEntry.getDocType()); jg.writeStringField("docUUID", logEntry.getDocUUID()); jg.writeStringField("eventId", logEntry.getEventId()); jg.writeStringField("repositoryId", logEntry.getRepositoryId()); jg.writeStringField( "eventDate", ISODateTimeFormat.dateTime().print(new DateTime(logEntry.getEventDate()))); jg.writeNumberField("id", logEntry.getId()); jg.writeStringField( "logDate", ISODateTimeFormat.dateTime().print(new DateTime(logEntry.getLogDate()))); writeExtendedInfos(jg, logEntry); }
@Override public void run() { try { // command metrics for (HystrixCommandMetrics commandMetrics : HystrixCommandMetrics.getInstances()) { HystrixCommandKey key = commandMetrics.getCommandKey(); HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(key); StringWriter jsonString = new StringWriter(); JsonGenerator json = jsonFactory.createJsonGenerator(jsonString); // Informational and Status json.writeStartObject(); json.writeStringField(type.value, HystrixCommand.value); json.writeStringField(name.value, key.name()); json.writeStringField(group.value, commandMetrics.getCommandGroup().name()); json.writeNumberField(currentTime.value, (int) (System.currentTimeMillis() / 1000)); // circuit breaker json.writeBooleanField(isCircuitBreakerOpen.value, circuitBreaker.isOpen()); HystrixCommandMetrics.HealthCounts healthCounts = commandMetrics.getHealthCounts(); json.writeNumberField(errorPercentage.value, healthCounts.getErrorPercentage()); json.writeNumberField(errorCount.value, healthCounts.getErrorCount()); json.writeNumberField(requestCount.value, healthCounts.getTotalRequests()); // rolling counters Gauge json.writeNumberField( rollingCountCollapsedRequests.value, commandMetrics.getRollingCount(HystrixRollingNumberEvent.COLLAPSED)); json.writeNumberField( rollingCountExceptionsThrown.value, commandMetrics.getRollingCount(HystrixRollingNumberEvent.EXCEPTION_THROWN)); json.writeNumberField( rollingCountFailure.value, commandMetrics.getRollingCount(HystrixRollingNumberEvent.FAILURE)); json.writeNumberField( rollingCountFallbackFailure.value, commandMetrics.getRollingCount(HystrixRollingNumberEvent.FALLBACK_FAILURE)); json.writeNumberField( rollingCountFallbackRejection.value, commandMetrics.getRollingCount(HystrixRollingNumberEvent.FALLBACK_REJECTION)); json.writeNumberField( rollingCountFallbackSuccess.value, commandMetrics.getRollingCount(HystrixRollingNumberEvent.FALLBACK_SUCCESS)); json.writeNumberField( rollingCountResponsesFromCache.value, commandMetrics.getRollingCount(HystrixRollingNumberEvent.RESPONSE_FROM_CACHE)); json.writeNumberField( rollingCountSemaphoreRejected.value, commandMetrics.getRollingCount(HystrixRollingNumberEvent.SEMAPHORE_REJECTED)); json.writeNumberField( rollingCountShortCircuited.value, commandMetrics.getRollingCount(HystrixRollingNumberEvent.SHORT_CIRCUITED)); json.writeNumberField( rollingCountSuccess.value, commandMetrics.getRollingCount(HystrixRollingNumberEvent.SUCCESS)); json.writeNumberField( rollingCountThreadPoolRejected.value, commandMetrics.getRollingCount(HystrixRollingNumberEvent.THREAD_POOL_REJECTED)); json.writeNumberField( rollingCountTimeout.value, commandMetrics.getRollingCount(HystrixRollingNumberEvent.TIMEOUT)); json.writeNumberField( currentConcurrentExecutionCount.value, commandMetrics.getCurrentConcurrentExecutionCount()); // latency percentiles json.writeNumberField(latencyExecute_mean.value, commandMetrics.getExecutionTimeMean()); json.writeObjectFieldStart(latencyExecute.value); json.writeNumberField("0", commandMetrics.getExecutionTimePercentile(0)); json.writeNumberField("25", commandMetrics.getExecutionTimePercentile(25)); json.writeNumberField("50", commandMetrics.getExecutionTimePercentile(50)); json.writeNumberField("75", commandMetrics.getExecutionTimePercentile(75)); json.writeNumberField("90", commandMetrics.getExecutionTimePercentile(90)); json.writeNumberField("95", commandMetrics.getExecutionTimePercentile(95)); json.writeNumberField("99", commandMetrics.getExecutionTimePercentile(99)); json.writeNumberField("99.5", commandMetrics.getExecutionTimePercentile(99.5)); json.writeNumberField("100", commandMetrics.getExecutionTimePercentile(100)); json.writeEndObject(); // json.writeNumberField(latencyTotal_mean.value, commandMetrics.getTotalTimeMean()); json.writeObjectFieldStart(latencyTotal.value); json.writeNumberField("0", commandMetrics.getTotalTimePercentile(0)); json.writeNumberField("25", commandMetrics.getTotalTimePercentile(25)); json.writeNumberField("50", commandMetrics.getTotalTimePercentile(50)); json.writeNumberField("75", commandMetrics.getTotalTimePercentile(75)); json.writeNumberField("90", commandMetrics.getTotalTimePercentile(90)); json.writeNumberField("95", commandMetrics.getTotalTimePercentile(95)); json.writeNumberField("99", commandMetrics.getTotalTimePercentile(99)); json.writeNumberField("99.5", commandMetrics.getTotalTimePercentile(99.5)); json.writeNumberField("100", commandMetrics.getTotalTimePercentile(100)); json.writeEndObject(); // property values for reporting what is actually seen by the command rather than what was // set somewhere HystrixCommandProperties commandProperties = commandMetrics.getProperties(); json.writeNumberField( propertyValue_circuitBreakerRequestVolumeThreshold.value, commandProperties.circuitBreakerRequestVolumeThreshold().get()); json.writeNumberField( propertyValue_circuitBreakerSleepWindowInMilliseconds.value, commandProperties.circuitBreakerSleepWindowInMilliseconds().get()); json.writeNumberField( propertyValue_circuitBreakerErrorThresholdPercentage.value, commandProperties.circuitBreakerErrorThresholdPercentage().get()); json.writeBooleanField( propertyValue_circuitBreakerForceOpen.value, commandProperties.circuitBreakerForceOpen().get()); json.writeBooleanField( propertyValue_circuitBreakerForceClosed.value, commandProperties.circuitBreakerForceClosed().get()); json.writeBooleanField( propertyValue_circuitBreakerEnabled.value, commandProperties.circuitBreakerEnabled().get()); json.writeStringField( propertyValue_executionIsolationStrategy.value, commandProperties.executionIsolationStrategy().get().name()); json.writeNumberField( propertyValue_executionIsolationThreadTimeoutInMilliseconds.value, commandProperties.executionIsolationThreadTimeoutInMilliseconds().get()); json.writeBooleanField( propertyValue_executionIsolationThreadInterruptOnTimeout.value, commandProperties.executionIsolationThreadInterruptOnTimeout().get()); json.writeStringField( propertyValue_executionIsolationThreadPoolKeyOverride.value, commandProperties.executionIsolationThreadPoolKeyOverride().get()); json.writeNumberField( propertyValue_executionIsolationSemaphoreMaxConcurrentRequests.value, commandProperties.executionIsolationSemaphoreMaxConcurrentRequests().get()); json.writeNumberField( propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests.value, commandProperties.fallbackIsolationSemaphoreMaxConcurrentRequests().get()); /* * The following are commented out as these rarely change and are verbose for streaming for something people don't change. * We could perhaps allow a property or request argument to include these. */ // json.put("propertyValue_metricsRollingPercentileEnabled", // commandProperties.metricsRollingPercentileEnabled().get()); // json.put("propertyValue_metricsRollingPercentileBucketSize", // commandProperties.metricsRollingPercentileBucketSize().get()); // json.put("propertyValue_metricsRollingPercentileWindow", // commandProperties.metricsRollingPercentileWindowInMilliseconds().get()); // json.put("propertyValue_metricsRollingPercentileWindowBuckets", // commandProperties.metricsRollingPercentileWindowBuckets().get()); // json.put("propertyValue_metricsRollingStatisticalWindowBuckets", // commandProperties.metricsRollingStatisticalWindowBuckets().get()); json.writeNumberField( propertyValue_metricsRollingStatisticalWindowInMilliseconds.value, commandProperties.metricsRollingStatisticalWindowInMilliseconds().get()); json.writeBooleanField( propertyValue_requestCacheEnabled.value, commandProperties.requestCacheEnabled().get()); json.writeBooleanField( propertyValue_requestLogEnabled.value, commandProperties.requestLogEnabled().get()); json.writeNumberField(reportingHosts.value, 1); json.writeStringField(Key.ip.value, app_ip); json.writeEndObject(); json.close(); // System.out.println(ip + ":" + port + "||" + // jsonString.getBuffer().toString()); UDPClient.send( socketIp, socketPort, jsonString.getBuffer().toString().getBytes(), new byte[] {}); } // thread pool metrics for (HystrixThreadPoolMetrics threadPoolMetrics : HystrixThreadPoolMetrics.getInstances()) { HystrixThreadPoolKey key = threadPoolMetrics.getThreadPoolKey(); StringWriter jsonString = new StringWriter(); JsonGenerator json = jsonFactory.createJsonGenerator(jsonString); json.writeStartObject(); json.writeStringField(type.value, HystrixThreadPool.value); json.writeStringField(name.value, key.name()); json.writeNumberField(currentTime.value, System.currentTimeMillis()); // 101.3 80 154 json.writeNumberField( currentActiveCount.value, threadPoolMetrics.getCurrentActiveCount().intValue()); json.writeNumberField( currentCompletedTaskCount.value, threadPoolMetrics.getCurrentCompletedTaskCount().longValue()); json.writeNumberField( currentCorePoolSize.value, threadPoolMetrics.getCurrentCorePoolSize().intValue()); json.writeNumberField( currentLargestPoolSize.value, threadPoolMetrics.getCurrentLargestPoolSize().intValue()); json.writeNumberField( currentMaximumPoolSize.value, threadPoolMetrics.getCurrentMaximumPoolSize().intValue()); json.writeNumberField( currentPoolSize.value, threadPoolMetrics.getCurrentPoolSize().intValue()); json.writeNumberField( currentQueueSize.value, threadPoolMetrics.getCurrentQueueSize().intValue()); json.writeNumberField( currentTaskCount.value, threadPoolMetrics.getCurrentTaskCount().longValue()); json.writeNumberField( rollingCountThreadsExecuted.value, threadPoolMetrics.getRollingCountThreadsExecuted()); json.writeNumberField( rollingMaxActiveThreads.value, threadPoolMetrics.getRollingMaxActiveThreads()); json.writeNumberField( propertyValue_queueSizeRejectionThreshold.value, threadPoolMetrics.getProperties().queueSizeRejectionThreshold().get()); json.writeNumberField( propertyValue_metricsRollingStatisticalWindowInMilliseconds.value, threadPoolMetrics .getProperties() .metricsRollingStatisticalWindowInMilliseconds() .get()); json.writeNumberField( reportingHosts.value, 1); // this will get summed across all instances in a cluster json.writeStringField(Key.ip.value, app_ip); json.writeEndObject(); json.close(); String str = jsonString.getBuffer().toString(); byte[] ret = str.getBytes(); UDPClient.send(socketIp, socketPort, ret, new byte[] {}); } } catch (Exception e) { System.err.println("Failed to output metrics as JSON"); e.printStackTrace(); } }
public static void writeNeuronCoreTop( EDSimulation sim, StringBuilder sb, JsonGenerator g, Map<String, Float> initialState, String neuronName) throws JsonGenerationException, IOException { currentBit = 511; // 5119; currentLength = 0; Integer = 0; sb.append( "\r\n" + "library ieee;\r\n" + "use ieee.std_logic_1164.all;\r\n" + "use ieee.std_logic_unsigned.all;\r\n" + "library ieee_proposed;\r\n" + "use ieee_proposed.fixed_pkg.all;\r\n" + "use ieee_proposed.fixed_float_types.ALL;\r\n" + "use std.textio.all;\r\n" + "use ieee.std_logic_textio.all; -- if you're saving this type of signal\r\n" + "use IEEE.numeric_std.all;\r\n" + ""); sb.append( "\r\n" + "entity neuroncore_top is\r\n" + " Port ( clk : in STD_LOGIC; --SYSTEM CLOCK, THIS ITSELF DOES NOT SIGNIFY TIME STEPS - AKA A SINGLE TIMESTEP MAY TAKE MANY CLOCK CYCLES\r\n" + " init_model : in STD_LOGIC; --SYNCHRONOUS RESET\r\n" + " step_once_go : in STD_LOGIC; --signals to the neuron from the core that a time step is to be simulated\r\n" + " step_once_complete : out STD_LOGIC; --signals to the core that a time step has finished\r\n" + " \r\n" + " mega_bus_in : in STD_LOGIC_Vector (99999 downto 0 );\r\n" + " mega_bus_out : out STD_LOGIC_Vector (99999 downto 0 )\r\n" + " );\r\n" + "end neuroncore_top;\r\n" + "\r\n" + "---------------------------------------------------------------------\r\n" + "\r\n" + "architecture top of neuroncore_top is\r\n"); EDComponent neuron = sim.neuronComponents.get(0); for (int i = 0; i < sim.neuronComponents.size(); i++) { if (sim.neuronComponents.get(i).name.matches(neuronName)) { neuron = sim.neuronComponents.get(i); break; } } sb.append( "\r\n" + "component top_synth\r\n" + " Port ( clk : in STD_LOGIC; --SYSTEM CLOCK, THIS ITSELF DOES NOT SIGNIFY TIME STEPS - AKA A SINGLE TIMESTEP MAY TAKE MANY CLOCK CYCLES\r\n" + " init_model : in STD_LOGIC; --SYNCHRONOUS RESET\r\n" + " step_once_go : in STD_LOGIC; --signals to the neuron from the core that a time step is to be simulated\r\n" + " step_once_complete : out STD_LOGIC; --signals to the core that a time step has finished\r\n" + " eventport_in_spike_aggregate : in STD_LOGIC_VECTOR(511 downto 0);\r\n" + // " SelectSpikesIn : in STD_LOGIC_VECTOR(4607 downto 0);\r\n" + " "); String name = ""; for (Iterator<EDEventPort> i = neuron.eventports.iterator(); i.hasNext(); ) { EDEventPort item = i.next(); sb.append( " " + neuron.name + "_eventport_" + item.direction + "_" + item.name + " : " + item.direction + " STD_LOGIC;\r\n"); } if (neuron.regimes.size() > 0) { sb.append( " " + neuron.name + "current_regime_in_stdlv : in STD_LOGIC_VECTOR(1 downto 0);\r\n" + " " + neuron.name + "current_regime_out_stdlv : out STD_LOGIC_VECTOR(1 downto 0);\r\n"); } TopSynth.writeEntitySignals(neuron, sb, name, neuron.name + "_"); sb.append( "\r\n" + " sysparam_time_timestep : sfixed (-6 downto -22);\r\n" + " sysparam_time_simtime : sfixed (6 downto -22)\r\n" + " );\r\n" + "end component;\r\n" + "\r\n" + "\r\n" + " \r\n" + " "); for (Iterator<EDEventPort> i = neuron.eventports.iterator(); i.hasNext(); ) { EDEventPort item = i.next(); sb.append( "signal " + neuron.name + "_eventport_" + item.direction + "_" + item.name + "_internal : std_logic;\r\n"); } if (neuron.regimes.size() > 0) { sb.append( "signal " + neuron.name + "_current_regime_out_stdlv_int : STD_LOGIC_VECTOR(1 downto 0);\r\n"); } writeStateSignals(neuron, sb, "", neuron.name); g.writeObjectFieldStart(neuron.name); g.writeObjectFieldStart("SpikesIn"); g.writeNumberField("bottom", 0); g.writeNumberField("top", 511); g.writeEndObject(); g.writeArrayFieldStart("NeuronVariablesIn"); sb.append( "begin\r\n" + "\r\n" + "top_synth_uut : neuron_model \r\n" + " port map ( clk => clk,\r\n" + " init_model => init_model, \r\n" + " step_once_go => step_once_go,\r\n" + " step_once_complete => step_once_complete,\r\n" + " eventport_in_spike_aggregate => mega_bus_in(511 downto 0),\r\n" + // " SelectSpikesIn => mega_bus_in(5119 downto 512),\r\n" + " "); for (Iterator<EDEventPort> i = neuron.eventports.iterator(); i.hasNext(); ) { EDEventPort item = i.next(); sb.append( " " + neuron.name + "_eventport_" + item.direction + "_" + item.name + " => " + neuron.name + "_eventport_" + item.direction + "_" + item.name + "_internal ,\r\n"); } if (neuron.regimes.size() > 0) { currentBit = currentBit + currentLength + 1; while (currentBit % 8 != 0) currentBit++; currentLength = 1; int currentTop = currentBit + currentLength; writeSignal("regime", currentBit, currentTop, 0, 0, g); sb.append( "" + neuron.name + "current_regime_in_stdlv => mega_bus_in(" + currentTop + " downto " + currentBit + "),\r\n"); sb.append( "" + neuron.name + "current_regime_out_stdlv => " + neuron.name + "_current_regime_out_stdlv_int,\r\n"); } writeConnectivityMapVar(neuron, sb, "", neuron.name, g); g.writeEndArray(); g.writeArrayFieldStart("NeuronParameters"); writeConnectivityMapPar(neuron, sb, "", neuron.name, g); currentBit = currentBit + currentLength + 1; currentLength = 16; int currentTop = currentBit + currentLength; sb.append( "sysparam_time_timestep => to_sfixed (mega_bus_in(" + currentTop + " downto " + currentBit + "),-6 , -22),"); currentBit = currentBit + currentLength + 1; currentLength = 28; currentTop = currentBit + currentLength; sb.append( "sysparam_time_simtime => to_sfixed (mega_bus_in(" + currentTop + " downto " + currentBit + "),6, -22)"); sb.append("\r\n" + " );\r\n"); g.writeEndArray(); g.writeArrayFieldStart("NeuronVariablesOut"); currentBit = -1; currentLength = 0; if (neuron.regimes.size() > 0) { currentBit = currentBit + currentLength + 1; while (currentBit % 8 != 0) currentBit++; currentLength = 1; currentTop = currentBit + currentLength; writeSignal("regime", currentBit, currentTop, 0, 0, g); sb.append( " mega_bus_out(" + currentTop + " downto " + currentBit + ") <= " + neuron.name + "_current_regime_out_stdlv_int;\r\n"); } writeStateToBusSignals(neuron, sb, "", neuron.name, g); for (Iterator<EDEventPort> i = neuron.eventports.iterator(); i.hasNext(); ) { EDEventPort item = i.next(); currentBit = currentBit + currentLength + 1; while (currentBit % 8 != 0) currentBit++; sb.append( " mega_bus_out(" + currentBit + ") <= " + neuron.name + "_eventport_" + item.direction + "_" + item.name + "_internal;\r\n"); } sb.append("\r\n" + "end top;\r\n" + ""); g.writeEndArray(); g.writeEndObject(); }
public void testWritePrimitiveWithFloat() throws Exception { generator.writeNumberField("foo", 0.5f); replayMocks(); nullSafeWritePrimitiveField(generator, "foo", 0.5f); verifyMocks(); }