org.apache.avro.Protocol Java Examples
The following examples show how to use
org.apache.avro.Protocol.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractRequestInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { if (objInst.getSkyWalkingDynamicField() == null) { Requestor requestor = (Requestor) objInst; requestor.addRPCPlugin(new SWClientRPCPlugin()); Protocol protocol = (Protocol) allArguments[0]; Transceiver transceiver = (Transceiver) allArguments[1]; try { objInst.setSkyWalkingDynamicField(new AvroInstance(protocol.getNamespace() + "." + protocol.getName() + ".", transceiver .getRemoteName())); } catch (IOException e) { objInst.setSkyWalkingDynamicField(new AvroInstance("Undefined", "Undefined")); logger.error("Failed to get Avro Remote Client Information.", e); } } }
Example #2
Source File: ResponderInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void onConstruct(EnhancedInstance enhancedInstance, Object[] objects) { Responder responder = (Responder) enhancedInstance; Protocol protocol = responder.getLocal(); String prefix = protocol.getNamespace() + "." + protocol.getName() + "."; responder.addRPCPlugin(new SWServerRPCPlugin(prefix)); }
Example #3
Source File: GenerateAvroJavaTask.java From gradle-avro-plugin with Apache License 2.0 | 5 votes |
private void processProtoFile(File sourceFile) { getLogger().info("Processing {}", sourceFile); try { compile(new SpecificCompiler(Protocol.parse(sourceFile)), sourceFile); } catch (IOException ex) { throw new GradleException(String.format("Failed to compile protocol definition file %s", sourceFile), ex); } }
Example #4
Source File: GenerateAvroSchemaTask.java From gradle-avro-plugin with Apache License 2.0 | 5 votes |
private void processProtoFile(File sourceFile) { getLogger().info("Processing {}", sourceFile); try { Protocol protocol = Protocol.parse(sourceFile); for (Schema schema : protocol.getTypes()) { String path = schema.getNamespace().replaceAll(Pattern.quote("."), "/"); File schemaFile = new File(getOutputDir().get().getAsFile(), path + "/" + schema.getName() + "." + SCHEMA_EXTENSION); String schemaJson = schema.toString(true); FileUtils.writeJsonFile(schemaFile, schemaJson); getLogger().debug("Wrote {}", schemaFile.getPath()); } } catch (IOException ex) { throw new GradleException(String.format("Failed to process protocol definition file %s", sourceFile), ex); } }
Example #5
Source File: ExpressionCallTest.java From depends with MIT License | 4 votes |
public GenericRequestor(Protocol protocol, Transceiver transceiver) throws IOException { this(protocol, transceiver, GenericData.get()); }
Example #6
Source File: GenerateSchemas.java From bunsen with Apache License 2.0 | 4 votes |
/** * Main entrypoint for schema generation tool. * * @param args the output file followed by a list of resource type urls * @return the OS status code */ public static int main(String[] args) { if (args.length < 2) { System.out.println("Usage: GenerateSchemas <output file> resourceTypeUrls..."); System.out.println("Example:"); System.out.println(" GenerateSchemas my_schemas.avsc " + "http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient " + "http://hl7.org/fhir/us/core/StructureDefinition/us-core-condition"); System.out.println(); System.out.println("The resulting avsc file then can be used to generate Java classes " + "using avro-tools, for example:"); System.out.println(" avro-tools compile protocol my_schemas.avsc <target_directory>"); return 1; } File outputFile = new File(args[0]); if (outputFile.exists()) { System.out.println("File " + outputFile.getName() + " already exists."); return 1; } Map<String, List<String>> resourceTypeUrls = Arrays.stream(args) .skip(1) .collect(Collectors.toMap(Function.identity(), item -> Collections.emptyList())); List<Schema> schemas = AvroConverter.generateSchemas(FhirContexts.forStu3(), resourceTypeUrls); // Wrap the schemas in a protocol to simplify the invocation of the compiler. Protocol protocol = new Protocol("FhirGeneratedSchemas", "Avro schemas generated from FHIR StructureDefinitions", "com.cerner.bunsen.avro"); protocol.setTypes(schemas); try { Files.write(outputFile.toPath(), protocol.toString(true).getBytes()); } catch (IOException exception) { System.out.println("Unable to write file " + outputFile.getPath()); exception.printStackTrace(); return 1; } return 0; }
Example #7
Source File: AvroConverterTest.java From bunsen with Apache License 2.0 | 4 votes |
@Test public void testCompile() throws IOException { List<Schema> schemas = AvroConverter.generateSchemas(FhirContexts.forStu3(), ImmutableMap.of(TestData.US_CORE_PATIENT, Collections.emptyList(), TestData.VALUE_SET, Collections.emptyList(), TestData.US_CORE_MEDICATION_REQUEST, ImmutableList.of(TestData.US_CORE_MEDICATION))); // Wrap the schemas in a protocol to simplify the invocation of the compiler. Protocol protocol = new Protocol("fhir-test", "FHIR Resources for Testing", null); protocol.setTypes(schemas); SpecificCompiler compiler = new SpecificCompiler(protocol); Path generatedCodePath = Files.createTempDirectory("generated_code"); generatedCodePath.toFile().deleteOnExit(); compiler.compileToDestination(null, generatedCodePath.toFile()); // Check that java files were created as expected. Set<String> javaFiles = Files.find(generatedCodePath, 10, (path, basicFileAttributes) -> true) .map(path -> generatedCodePath.relativize(path)) .map(Object::toString) .collect(Collectors.toSet()); // Ensure common types were generated Assert.assertTrue(javaFiles.contains("com/cerner/bunsen/stu3/avro/Period.java")); Assert.assertTrue(javaFiles.contains("com/cerner/bunsen/stu3/avro/Coding.java")); Assert.assertTrue(javaFiles.contains("com/cerner/bunsen/stu3/avro/ValueSet.java")); // The specific profile should be created in the expected sub-package. Assert.assertTrue(javaFiles.contains("com/cerner/bunsen/stu3/avro/us/core/Patient.java")); // Check extension types. Assert.assertTrue(javaFiles.contains("com/cerner/bunsen/stu3/avro/us/core/UsCoreRace.java")); // Choice types include each choice that could be used. Assert.assertTrue(javaFiles.contains("com/cerner/bunsen/stu3/avro/ChoiceBooleanInteger.java")); // Contained types created. Assert.assertTrue(javaFiles.contains( "com/cerner/bunsen/stu3/avro/us/core/MedicationRequestContained.java")); }