ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/tribes/demos/MembersWithProperties.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/tribes/demos/MembersWithProperties.java
Status
scanned
Type
file
Name
MembersWithProperties.java
Extension
.java
Programming language
Java
Mime type
text/x-c
File type
C source, ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
4776 (4.7 KB)
MD5
2231d0c5cba4584e3b4ba8df790ff827
SHA1
bf7c0d973d8cd95f5b8a4488f4e4f5ff7bd837e3
SHA256
d13619c8ae634a356c398715d1a2c6d6fe06805ca18f952cc1199da3b7d403b5
SHA512

      
    
SHA1_git
ee3a1c313e1908785ae1e71e6352cfb6b4a9e520
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
MembersWithProperties.java | 4.7 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ package org.apache.catalina.tribes.demos; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Properties; import org.apache.catalina.tribes.Channel; import org.apache.catalina.tribes.ManagedChannel; import org.apache.catalina.tribes.Member; import org.apache.catalina.tribes.MembershipListener; import org.apache.catalina.tribes.util.Arrays; import org.apache.catalina.tribes.util.UUIDGenerator; public class MembersWithProperties implements MembershipListener { static Thread main; public MembersWithProperties(Channel channel, Properties props) throws IOException { channel.addMembershipListener(this); ManagedChannel mchannel = (ManagedChannel) channel; mchannel.getMembershipService().setPayload(getPayload(props)); } byte[] getPayload(Properties props) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); props.store(bout, ""); return bout.toByteArray(); } Properties getProperties(byte[] payload) throws IOException { ByteArrayInputStream bin = new ByteArrayInputStream(payload); Properties props = new Properties(); props.load(bin); return props; } @Override public void memberAdded(Member member) { try { System.out.println("Received member added:" + member); System.out.println("Payload[" + member + "] :"); getProperties(member.getPayload()).store(System.out, ""); } catch (Exception x) { x.printStackTrace(); } } @Override public void memberDisappeared(Member member) { try { System.out.println("Received member disappeared:" + member); System.out.println("Payload[" + member + "] :"); getProperties(member.getPayload()).store(System.out, ""); } catch (Exception x) { x.printStackTrace(); } } public static void usage() { System.out.println("Tribes Member Properties demo."); System.out.println("Usage: " + "java MemberWithProperties " + "Channel options:" + ChannelCreator.usage() + " " + "Example: " + "java MembersWithProperties -port 4004 " + "java MembersWithProperties -bind 192.168.0.45 -port 4005 " + "java MembersWithProperties -bind 192.168.0.45 -port 4005 -mbind 192.168.0.45 -count 100 -stats 10 "); } @SuppressWarnings("unused") public static void main(String[] args) throws Exception { if (args.length == 0) { usage(); } main = Thread.currentThread(); ManagedChannel channel = (ManagedChannel) ChannelCreator.createChannel(args); Properties props = new Properties(); props.setProperty("mydomainkey", "mydomainvalue"); props.setProperty("someotherkey", Arrays.toString(UUIDGenerator.randomUUID(true))); new MembersWithProperties(channel, props); channel.start(Channel.DEFAULT); Runtime.getRuntime().addShutdownHook(new Shutdown(channel)); try { Thread.sleep(Long.MAX_VALUE); } catch (InterruptedException ix) { Thread.sleep(5000);// allow everything to shutdown } } public static class Shutdown extends Thread { ManagedChannel channel = null; public Shutdown(ManagedChannel channel) { this.channel = channel; } @Override public void run() { System.out.println("Shutting down..."); try { channel.stop(Channel.DEFAULT); } catch (Exception x) { x.printStackTrace(); } System.out.println("Channel stopped."); main.interrupt(); } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
25.54
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9