Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ class GettingFile extends PerformingOperationState {
* @param pillar The pillar the file should be requested from.
*/
public GettingFile(GetFileConversationContext context, SelectedComponentInfo pillar) {
super(pillar.getID());
super(pillar.componentID());
this.context = context;
this.selectedPillar = pillar;
contributors = new HashSet<>();
contributors.add(pillar.getID());
contributors.add(pillar.componentID());
}

@Override
Expand All @@ -66,8 +66,8 @@ protected void sendRequest() {
msg.setFileAddress(context.getUrlForResult().toExternalForm());
msg.setFileID(context.getFileID());
msg.setFilePart(context.getFilePart());
msg.setPillarID(selectedPillar.getID());
msg.setDestination(selectedPillar.getDestination());
msg.setPillarID(selectedPillar.componentID());
msg.setDestination(selectedPillar.componentTopic());
context.getMonitor().requestSent("Sending GetFileRequest to ", selectedPillar.toString());
context.getMessageSender().sendMessage(msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void start() {
if (!responseStatus.getOutstandingComponents().isEmpty()) {
if (getTimeoutValue().compareTo(Duration.ZERO) > 0) { // TODO From Java 18 use: getTimeoutValue().isPositive()
CountAndTimeUnit delay = TimeUtils.durationToCountAndTimeUnit(getTimeoutValue());
scheduledTimeout = timer.schedule(new TimeoutHandler(), delay.getCount(), delay.getUnit());
scheduledTimeout = timer.schedule(new TimeoutHandler(), delay.count(), delay.unit());
}
sendRequest();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected void handleFailureResponse(MessageResponse msg) throws UnableToFinishE
private void generateContributorsSelectedEvent(Collection<SelectedComponentInfo> selectedComponentInfo) {
List<String> selectedComponentIDs = new LinkedList<>();
for (SelectedComponentInfo componentInfo : selectedComponentInfo) {
selectedComponentIDs.add(componentInfo.getID());
selectedComponentIDs.add(componentInfo.componentID());
}
getContext().getMonitor().contributorsSelected(selectedComponentIDs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected PerformingOperationState(Collection<SelectedComponentInfo> expectedCon
super(toComponentIDs(expectedContributors));
this.activeContributors = new HashMap<>();
for (SelectedComponentInfo contributorInfo : expectedContributors) {
activeContributors.put(contributorInfo.getID(), contributorInfo.getDestination());
activeContributors.put(contributorInfo.componentID(), contributorInfo.componentTopic());
}
}

Expand Down Expand Up @@ -114,7 +114,7 @@ protected GeneralConversationState completeState() throws UnableToFinishExceptio
private static Collection<String> toComponentIDs(Collection<SelectedComponentInfo> contributors) {
Collection<String> componentIDs = new HashSet<>();
for (SelectedComponentInfo componentInfo : contributors) {
componentIDs.add(componentInfo.getID());
componentIDs.add(componentInfo.componentID());
}
return componentIDs;
}
Expand Down

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were Javadoc comments in this file before, and I consider that some of them were rather helpful. Can we fit in the same information in Javadoc comments on the record class?

In particular I don’t find it obvious that componentID is the ID of a pillar. On the other hand I don’t believe that getID() returns null in practice though one comment claims that it can.

Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,31 @@
*/
package org.bitrepository.client.conversation.selector;

import org.jspecify.annotations.NonNull;

/**
* Container for information about a pillar which as been identified and are marked as selected for a request.
* Container for information about a pillar which has been identified and marked as selected for a request.
*
* @param componentID The ID of the selected pillar
* @param componentTopic The topic for communication with the selected pillar
*/
public class SelectedComponentInfo {
/**
* The ID of the selected pillar
*/
protected final String componentID;
/**
* The topic for communication with the selected pillar
*/
protected final String componentTopic;
public record SelectedComponentInfo(@NonNull String componentID, @NonNull String componentTopic) {

@ole-v-v ole-v-v Aug 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish I knew whether componentTopic was the right name for this field.

  • The name used in some places in the old class and agrees with some of the Javadoc comments.
  • On the other hand ComponentSelector feeds a “reply to” value into the field, and GettingFile uses the value as a destination. Also the name of the getter getDestination() supports this interpretation.

Let it be or add the alternative interpretation to the Javadoc comment, for example “The topic or destination for comm...”.


/**
* @param componentID The ID of the pillar
* @param componentTopic the topic for communication with the selected pillar
* @return The ID of the pillar chosen by this selector
* @deprecated Use {@link #componentID()} instead
*/
public SelectedComponentInfo(String componentID, String componentTopic) {
super();
this.componentID = componentID;
this.componentTopic = componentTopic;
}

/**
* @return The ID of the pillar chosen by this selector if finished. If unfinished null is returned
*/
public String getID() {
@Deprecated(forRemoval = true)
public @NonNull String getID() {
return componentID;
}

/**
* @return If finished return the topic for sending messages to the pillar chosen by this selector.
* If unfinished null is returned
* @return The topic for sending messages to the pillar chosen by this selector
* @deprecated Use {@link #componentTopic()} instead
*/
public String getDestination() {
@Deprecated(forRemoval = true)
public @NonNull String getDestination() {
return componentTopic;
}

@Override
public String toString() {
return getClass().getSimpleName() + ": componentID=" + componentID + ", componentTopic=" + componentTopic;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public abstract class CompleteEventAwaiter implements EventHandler {
* @param settings The settings.
* @param outputHandler The {@link OutputHandler} for handling outputting results
*/
public CompleteEventAwaiter(Settings settings, OutputHandler outputHandler) {
protected CompleteEventAwaiter(Settings settings, OutputHandler outputHandler) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the class is abstract, I guess it’s OK to declare the constructor protected.

this.timeout = settings.getIdentificationTimeout().plus(settings.getOperationTimeout());
this.output = outputHandler;
}
Expand Down Expand Up @@ -88,7 +88,7 @@ public void handleEvent(OperationEvent event) {
public OperationEvent getFinish() {
try {
CountAndTimeUnit pollTimeout = TimeUtils.durationToCountAndTimeUnit(timeout);
return finalEventQueue.poll(pollTimeout.getCount(), pollTimeout.getUnit());
return finalEventQueue.poll(pollTimeout.count(), pollTimeout.unit());
} catch (InterruptedException e) {
throw new IllegalStateException("Interrupted while waiting for the final response.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void handleEvent(OperationEvent event) {
public OperationEvent getFinish() {
try {
CountAndTimeUnit pollTimeout = TimeUtils.durationToCountAndTimeUnit(timeout);
return finalEventQueue.poll(pollTimeout.getCount(), pollTimeout.getUnit());
return finalEventQueue.poll(pollTimeout.count(), pollTimeout.unit());
} catch (InterruptedException e) {
throw new IllegalStateException("Interrupted while waiting for the final response.", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.bitrepository.client.conversation.selector;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

@Tag("regressiontest")
class SelectedComponentInfoTest {

@Test
void delegationMethodsReturnCorrectComponents() {
SelectedComponentInfo info = new SelectedComponentInfo("pillar1", "pillar1-topic");
assertEquals("pillar1", info.getID());
assertEquals("pillar1-topic", info.getDestination());
}

@Test
void equalityIsComponentBased() {
SelectedComponentInfo a = new SelectedComponentInfo("p1", "t1");
SelectedComponentInfo b = new SelectedComponentInfo("p1", "t1");
assertEquals(a, b);
assertEquals(a.hashCode(), b.hashCode());
}

@Test
void toStringContainsComponentValues() {
String s = new SelectedComponentInfo("p1", "t1").toString();
assertTrue(s.contains("p1"));
assertTrue(s.contains("t1"));
}
}
6 changes: 3 additions & 3 deletions bitrepository-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
package org.bitrepository.common;

import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -55,7 +55,7 @@ public DefaultThreadFactory(String prefix, int priority, boolean daemonic) {
}

@Override
public synchronized Thread newThread(@NotNull Runnable runnable) {
public synchronized Thread newThread(@NonNull Runnable runnable) {
Thread newThread = new Thread(runnable, prefix + "-Thread" + counter);
newThread.setPriority(priority);
newThread.setDaemon(daemonic);
Expand Down

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This an example where for compatibility we still need to have a public File getFile() method (deprecated for removal if you like).

Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@
/**
* File info for the files of a default file system.
*/
public class DefaultFileInfo implements FileInfo {
private final File file;
public record DefaultFileInfo(File file) implements FileInfo {

public DefaultFileInfo(File file) {
this.file = file;
/**
* @deprecated Use {@link #file()} instead
*/
@Deprecated(forRemoval = true)
public File getFile() {
return file;
}

@Override
Expand All @@ -55,8 +58,4 @@ public Long getLastModifiedDate() {
public long getSize() {
return file.length();
}

public File getFile() {
return file;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,24 @@
import java.util.Objects;
import java.util.concurrent.TimeUnit;

public class CountAndTimeUnit {
private final long count;
private final TimeUnit unit;

public CountAndTimeUnit(long count, TimeUnit unit) {
this.count = count;
this.unit = Objects.requireNonNull(unit, "unit");
public record CountAndTimeUnit(long count, TimeUnit unit) {
public CountAndTimeUnit {
Objects.requireNonNull(unit, "unit");
}

/**
* @deprecated Use {@link #count()} instead
*/
@Deprecated(forRemoval = true)
public long getCount() {
return count;
}

/**
* @deprecated Use {@link #unit()} instead
*/
@Deprecated(forRemoval = true)
public TimeUnit getUnit() {
return unit;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CountAndTimeUnit that = (CountAndTimeUnit) o;
return count == that.count && unit == that.unit;
}

@Override
public int hashCode() {
return Objects.hash(count, unit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
package org.bitrepository.common.utils;

import org.bitrepository.common.ArgumentValidator;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NonNull;

import javax.xml.datatype.XMLGregorianCalendar;
import java.text.DateFormat;
Expand Down Expand Up @@ -191,7 +191,7 @@ public static String humanDifference(ZonedDateTime start, ZonedDateTime end) {
return humanPeriodAndDuration(periodBetween, durationBetween);
}

@NotNull
@NonNull
private static String humanPeriodAndDuration(Period period, Duration dur) {
// Round duration to whole minutes
dur = dur.plusSeconds(30).truncatedTo(ChronoUnit.MINUTES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
/**
* Contains information about the message, not contained in the message itself.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside this task, may delete the comma.

*/
public class MessageContext {
private final String certificateFingerprint;

public MessageContext(String certificateFingerprint) {
this.certificateFingerprint = certificateFingerprint;
}

public record MessageContext(String certificateFingerprint) {
/**
* @deprecated Use {@link #certificateFingerprint()} instead
*/
@Deprecated(forRemoval = true)
public String getCertificateFingerprint() {
return certificateFingerprint;
}
Expand Down
Loading