Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Grundlefleck/plugin-pull-request
Plugin pull request
- Loading branch information
Showing
31 changed files
with
420 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/org/netmelody/cieye/core/observation/ForeignAgencies.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.netmelody.cieye.core.observation; | ||
|
||
import org.netmelody.cieye.core.domain.CiServerType; | ||
|
||
public interface ForeignAgencies { | ||
ObservationAgency agencyFor(CiServerType type); | ||
|
||
void registerInterestInChanges(Object interested); | ||
|
||
final class RosterChangedEvent {} | ||
} |
3 changes: 2 additions & 1 deletion
3
src/main/java/org/netmelody/cieye/core/observation/ObservationAgency.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package org.netmelody.cieye.core.observation; | ||
|
||
import org.netmelody.cieye.core.domain.CiServerType; | ||
import org.netmelody.cieye.core.domain.Feature; | ||
|
||
public interface ObservationAgency { | ||
|
||
boolean canProvideSpyFor(CiServerType type); | ||
CiSpy provideSpyFor(Feature feature, CommunicationNetwork network, KnownOffendersDirectory directory); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/org/netmelody/cieye/server/CiSpyIntermediary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.netmelody.cieye.server; | ||
|
||
import org.netmelody.cieye.core.domain.Feature; | ||
import org.netmelody.cieye.core.domain.TargetId; | ||
|
||
public interface CiSpyIntermediary { | ||
TargetGroupBriefing briefingOn(Feature feature); | ||
boolean passNoteOn(Feature feature, TargetId targetId, String note); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/org/netmelody/cieye/server/TargetGroupBriefing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.netmelody.cieye.server; | ||
|
||
import org.netmelody.cieye.core.domain.TargetDetailGroup; | ||
|
||
public final class TargetGroupBriefing { | ||
|
||
public final TargetDetailGroup status; | ||
public final long millisecondsUntilNextUpdate; | ||
|
||
public TargetGroupBriefing(TargetDetailGroup targetDetailGroup, long millisecondsUntilNextUpdate) { | ||
this.status = targetDetailGroup; | ||
this.millisecondsUntilNextUpdate = millisecondsUntilNextUpdate; | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/netmelody/cieye/server/configuration/PluginDirectory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.netmelody.cieye.server.configuration; | ||
|
||
import java.io.File; | ||
import java.io.FileFilter; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.Date; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.io.filefilter.SuffixFileFilter; | ||
|
||
public final class PluginDirectory { | ||
|
||
private final File directory; | ||
private Date lastReadDate = new Date(0L); | ||
|
||
public PluginDirectory(File directory) { | ||
this.directory = directory; | ||
} | ||
|
||
public Iterable<File> jars() { | ||
lastReadDate = new Date(); | ||
File[] jarFiles = directory.listFiles((FileFilter)new SuffixFileFilter(".jar")); | ||
return jarFiles == null ? Collections.<File>emptySet() : Arrays.asList(jarFiles); | ||
} | ||
|
||
public boolean updateAvailable() { | ||
return FileUtils.isFileNewer(directory, lastReadDate); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
.../java/org/netmelody/cieye/server/configuration/ServiceLoadingRecordedForeignAgencies.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package org.netmelody.cieye.server.configuration; | ||
|
||
import java.io.File; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.util.Iterator; | ||
import java.util.ServiceLoader; | ||
import java.util.Set; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import org.netmelody.cieye.core.domain.CiServerType; | ||
import org.netmelody.cieye.core.logging.LogKeeper; | ||
import org.netmelody.cieye.core.logging.Logbook; | ||
import org.netmelody.cieye.core.observation.ForeignAgencies; | ||
import org.netmelody.cieye.core.observation.ObservationAgency; | ||
|
||
import com.google.common.collect.FluentIterable; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.collect.Sets; | ||
import com.google.common.eventbus.EventBus; | ||
|
||
public final class ServiceLoadingRecordedForeignAgencies implements ForeignAgencies, Refreshable { | ||
private final static Logbook LOGBOOK = LogKeeper.logbookFor(ServiceLoadingRecordedForeignAgencies.class); | ||
private final EventBus eventBus = new EventBus(getClass().getName()); | ||
|
||
private final PluginDirectory pluginDirectory; | ||
private final AtomicReference<ServiceLoader<ObservationAgency>> services; | ||
|
||
|
||
public ServiceLoadingRecordedForeignAgencies(PluginDirectory pluginDirectory) { | ||
this.pluginDirectory = pluginDirectory; | ||
this.services = new AtomicReference<ServiceLoader<ObservationAgency>>(newServiceLoader()); | ||
} | ||
|
||
@Override | ||
public ObservationAgency agencyFor(CiServerType type) { | ||
final String typeName = type.name(); | ||
Iterator<ObservationAgency> agencies = available(); | ||
|
||
while (agencies.hasNext()) { | ||
ObservationAgency agency = agencies.next(); | ||
if (agency.canProvideSpyFor(type)) { | ||
return agency; | ||
} | ||
} | ||
|
||
throw new IllegalStateException("No CI Observation Module for " + typeName); | ||
} | ||
|
||
private ServiceLoader<ObservationAgency> newServiceLoader() { | ||
return ServiceLoader.load(ObservationAgency.class, pluginsClassLoader()); | ||
} | ||
|
||
private Iterator<ObservationAgency> available() { | ||
return services.get().iterator(); | ||
} | ||
|
||
private ClassLoader pluginsClassLoader() { | ||
Iterable<File> jarFiles = pluginDirectory.jars(); | ||
return new URLClassLoader(FluentIterable.from(urlsOf(jarFiles)).toArray(URL.class)); | ||
} | ||
|
||
private Set<URL> urlsOf(Iterable<File> jarFiles) { | ||
Set<URL> urls = Sets.newHashSet(); | ||
Set<Throwable> problems = Sets.newHashSet(); | ||
for (File file : jarFiles) { | ||
try { | ||
urls.add(file.toURI().toURL()); | ||
} catch (MalformedURLException e) { | ||
problems.add(e); | ||
} | ||
} | ||
|
||
if (!problems.isEmpty()) { | ||
logProblems(problems); | ||
} | ||
|
||
return ImmutableSet.copyOf(urls); | ||
} | ||
|
||
private static void logProblems(Set<Throwable> problems) { | ||
System.out.printf("Found [%d] problems obtaining plugin jars. See logs for more details.%n", problems.size()); | ||
for (Throwable throwable : problems) { | ||
LOGBOOK.error("Error loading plugin.", throwable); | ||
} | ||
} | ||
|
||
@Override | ||
public void refresh() { | ||
if (pluginDirectory.updateAvailable()) { | ||
this.services.set(newServiceLoader()); | ||
this.eventBus.post(new RosterChangedEvent()); | ||
} | ||
} | ||
|
||
@Override | ||
public void registerInterestInChanges(Object interested) { | ||
this.eventBus.register(interested); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.