@Test public void shouldAppendToAStringBuilder() { StringBuilder builder = new StringBuilder("This example: "); Joiner.on(", ").appendTo(builder, ImmutableList.of("one", "two", "three")); assertEquals("This example: one, two, three", builder.toString()); }
public void onRestart() { joined.set(false); joiner.reset(); final String uuid = UuidUtil.createMemberUuid(address); logger.finest("Generated new UUID for local member: " + uuid); localMember.setUuid(uuid); }
public void join() { final long joinStartTime = joiner != null ? joiner.getStartTime() : Clock.currentTimeMillis(); final long maxJoinMillis = getGroupProperties().MAX_JOIN_SECONDS.getInteger() * 1000; try { if (joiner == null) { logger.warning("No join method is enabled! Starting standalone."); setAsMaster(); } else { joiner.join(joined); } } catch (Exception e) { if (Clock.currentTimeMillis() - joinStartTime < maxJoinMillis) { logger.warning("Trying to rejoin: " + e.getMessage()); rejoin(); } else { logger.severe("Could not join cluster, shutting down!", e); shutdown(false, true); } } }
private void join(File aFile) throws Exception { Properties theProperties = myProperties; String theLocalBaseDir = theProperties.getProperty("LOCALBASEDIR"); try { myMessage.stateChanged("JOIN"); myMessage.messageChanged(0, "In join"); myMessage.messageChanged(0, "My file name is " + aFile.getName()); myMessage.messageChanged(0, "My file full path is " + aFile.getPath()); // myMessage.messageChanged(0, "My MD5 value is "+MD5.getMD5(aFile)); /** * myMessage.messageChanged(0, "Delete files from "+theLocalTempDir); * * <p>File directory = new File(theLocalTempDir); // Get all files in directory File[] files * = directory.listFiles(); for (File file : files) { // Delete each file if * (!file.delete()) { // Failed to delete file System.out.println("Failed to delete "+file); * } }* */ myMessage.messageChanged(0, "Joining files into " + theLocalBaseDir); File theBaseDir = new File(theLocalBaseDir); Joiner theJoiner = new Joiner(aFile.getAbsolutePath(), theLocalBaseDir); /** * int theFileSplitSize = Integer.parseInt(theProperties.getProperty("LOCALFILESPLITSIZE")); * int theFileSplitBufferSize = * Integer.parseInt(theProperties.getProperty("LOCALFILESPLITBUFSIZE")); long * theNumIterations = (long)Math.ceil((float)aFile.length()/(float)theFileSplitSize); long * theCurrentIteration = 0; Splitter theSplitter = new * Splitter(aFile.getPath(),theLocalTempDir,theFileSplitSize,theFileSplitBufferSize); * myMessage.messageChanged(0, "Splitting FileName"+theSplitter.getNextTargetName());* */ long theNumIterations = theJoiner.getNumSplitFiles(); long theCurrentIteration = 0; while (theJoiner.moreToJoin() && !isCancelled()) { theJoiner.go(); theCurrentIteration++; if (theJoiner.moreToJoin()) { myMessage.messageChanged( (int) getPercentage(theCurrentIteration, theNumIterations), "Joining FileName" + theJoiner.getNextSourceName()); } } } catch (Exception e) { e.printStackTrace(); } if (!isCancelled()) { myMessage.messageChanged(100, "done"); } else { myMessage.messageChanged("Canceled in split"); } }
public ConfigCheck createConfigCheck() { final ConfigCheck configCheck = new ConfigCheck(); final GroupConfig groupConfig = config.getGroupConfig(); final PartitionGroupConfig partitionGroupConfig = config.getPartitionGroupConfig(); final boolean partitionGroupEnabled = partitionGroupConfig != null && partitionGroupConfig.isEnabled(); PartitionGroupConfig.MemberGroupType memberGroupType = partitionGroupEnabled ? partitionGroupConfig.getGroupType() : PartitionGroupConfig.MemberGroupType.PER_MEMBER; configCheck .setGroupName(groupConfig.getName()) .setGroupPassword(groupConfig.getPassword()) .setJoinerType(joiner != null ? joiner.getType() : "") .setPartitionGroupEnabled(partitionGroupEnabled) .setMemberGroupType(memberGroupType); return configCheck; }
private String resolveTypeDiscriminator(final Class<?> persistentType) { final List<String> discrimintators = new ArrayList<String>(); TypeDiscriminator td = persistentType.getAnnotation(TypeDiscriminator.class); if (td != null) { if (td.value().length() == 0) { throw new ViewGenerationException( String.format( "@TypeDiscriminator declared on type level must specify custom discriminator condition", persistentType)); } if (hasTypeDiscriminatorFieldOrMethod(persistentType)) { throw new ViewGenerationException( String.format( "@TypeDiscriminator declared on type level may not be combined with @TypeDiscriminator in fields or on methods", persistentType)); } return td.value(); } eachField( persistentType, new Predicate<Field>() { public boolean apply(Field input) { if (hasAnnotation(input, TypeDiscriminator.class)) { discrimintators.add("doc." + input.getName()); } return false; } }); eachMethod( persistentType, new Predicate<Method>() { public boolean apply(Method input) { if (hasAnnotation(input, TypeDiscriminator.class)) { discrimintators.add("doc." + firstCharToLowerCase(input.getName().substring(3))); } return true; } }); return Joiner.join(discrimintators, " && "); }
private void prepare() { Session s = openSession(); Transaction txn = s.beginTransaction(); polliwog = new Animal(); polliwog.setBodyWeight(12); polliwog.setDescription("Polliwog"); catepillar = new Animal(); catepillar.setBodyWeight(10); catepillar.setDescription("Catepillar"); frog = new Animal(); frog.setBodyWeight(34); frog.setDescription("Frog"); polliwog.setFather(frog); frog.addOffspring(polliwog); butterfly = new Animal(); butterfly.setBodyWeight(9); butterfly.setDescription("Butterfly"); catepillar.setMother(butterfly); butterfly.addOffspring(catepillar); s.save(frog); s.save(polliwog); s.save(butterfly); s.save(catepillar); Dog dog = new Dog(); dog.setBodyWeight(200); dog.setDescription("dog"); s.save(dog); Cat cat = new Cat(); cat.setBodyWeight(100); cat.setDescription("cat"); s.save(cat); zoo = new Zoo(); zoo.setName("Zoo"); Address add = new Address(); add.setCity("MEL"); add.setCountry("AU"); add.setStreet("Main st"); add.setPostalCode("3000"); zoo.setAddress(add); pettingZoo = new PettingZoo(); pettingZoo.setName("Petting Zoo"); Address addr = new Address(); addr.setCity("Sydney"); addr.setCountry("AU"); addr.setStreet("High st"); addr.setPostalCode("2000"); pettingZoo.setAddress(addr); s.save(zoo); s.save(pettingZoo); Joiner joiner = new Joiner(); joiner.setJoinedName("joined-name"); joiner.setName("name"); s.save(joiner); Car car = new Car(); car.setVin("123c"); car.setOwner("Kirsten"); s.save(car); Truck truck = new Truck(); truck.setVin("123t"); truck.setOwner("Steve"); s.save(truck); SUV suv = new SUV(); suv.setVin("123s"); suv.setOwner("Joe"); s.save(suv); Pickup pickup = new Pickup(); pickup.setVin("123p"); pickup.setOwner("Cecelia"); s.save(pickup); BooleanLiteralEntity bool = new BooleanLiteralEntity(); s.save(bool); txn.commit(); s.close(); }
public static void main(String[] args) { Sleeper sleepy01 = new Sleeper("Sleepy01", 1500), sleepy02 = new Sleeper("Sleepy02", 1500); Joiner joiner01 = new Joiner("Joiner01", sleepy01), joiner02 = new Joiner("Joiner02", sleepy02); joiner01.interrupt(); }
public String toString(String delim) { return Joiner.join(this, delim); }
@Test public void separatorShouldOnlyBeInsertedBetweenItems() { String joined = Joiner.on(".").join(ImmutableList.of("hello", "world")); assertEquals("hello.world", joined); }
@Test public void aSingleItemShouldNotBeJoinedWithAnything() { String joined = Joiner.on(",").join(ImmutableList.of("hello")); assertThat(joined, not(containsString(","))); }
@Test(expected = NullPointerException.class) public void separatorMustNotBeNull() { Joiner.on(null); }