Skip to content

Commit

Permalink
Fix streams
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberpwnn committed Jul 12, 2016
1 parent 4ac5fee commit 4655563
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<version>2.3.1</version>
<configuration>
<outputDirectory>${local.development}</outputDirectory>
<finalName>${project.name}-${project.version}</finalName>
<finalName>${project.name}</finalName>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public void fire(String channel, ExecutiveIterator<?> it)
pools.put(channel, new ExecutivePool((double) 1, 0));
}

pools.get(channel).add(it);

s("Funneled " + C.LIGHT_PURPLE + F.f(it.size()) + C.GREEN + " opterations into " + C.AQUA + channel + C.LIGHT_PURPLE + " " + F.f(pools.get(channel).size()) + C.GREEN + " total.");
}
}
15 changes: 14 additions & 1 deletion src/main/java/org/cyberpwn/phantom/Phantom.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,37 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.cyberpwn.phantom.construct.PhantomPlugin;
import org.cyberpwn.phantom.test.TestController;
import org.cyberpwn.phantom.sync.ExecutiveIterator;

public class Phantom extends PhantomPlugin
{
private static Phantom instance;
private ChanneledExecutivePoolController channeledExecutivePoolController;
private TestController testController;

public void enable()
{
testController = new TestController(this);
channeledExecutivePoolController = new ChanneledExecutivePoolController(this);
register(testController);
register(channeledExecutivePoolController);
instance = this;
}

public void disable()
{

}

public static void schedule(String channel, ExecutiveIterator<?> it)
{
instance.channeledExecutivePoolController.fire(channel, it);
}

public static void schedule(ExecutiveIterator<?> it)
{
instance.channeledExecutivePoolController.fire("default", it);
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.cyberpwn.phantom.test;
package org.cyberpwn.phantom;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
Expand All @@ -12,6 +13,8 @@
import org.cyberpwn.phantom.construct.Controller;
import org.cyberpwn.phantom.lang.GList;
import org.cyberpwn.phantom.lang.GMap;
import org.cyberpwn.phantom.sync.ExecutiveIterator;
import org.cyberpwn.phantom.sync.ExecutiveRunnable;

public class TestController extends Controller
{
Expand All @@ -23,6 +26,46 @@ public TestController(Controllable parentController)

tests = new GMap<String, Runnable>();

tests.put("channel-pool", new Runnable()
{
@Override
public void run()
{
GList<String> k = new GList<String>();
GList<String> v = new GList<String>();

for(int i = 0; i < 10240008 * Math.random(); i++)
{
k.add(UUID.randomUUID().toString());
}

v.qadd("alpha").qadd("beta").qadd("charlie").qadd("delta");

Phantom.schedule(new ExecutiveIterator<String>(k.copy(), new ExecutiveRunnable<String>()
{
public void run()
{
while(Math.random() < 0.6)
{
UUID.randomUUID();
Math.sqrt(Math.sqrt(Math.random()));
}

if(Math.random() < 0.001)
{
Phantom.schedule(v.pickRandom(), new ExecutiveIterator<String>(k.copy(), new ExecutiveRunnable<String>()
{
public void run()
{

}
}));
}
}
}));
}
});

tests.put("cluster-write", new Runnable()
{
@Override
Expand Down
14 changes: 3 additions & 11 deletions src/main/java/org/cyberpwn/phantom/sync/ExecutiveIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,18 @@
import java.util.Iterator;
import java.util.List;

import com.google.common.collect.Iterators;

public class ExecutiveIterator<T> implements Iterator<T>
{
private Iterator<T> it;
private ExecutiveRunnable<T> runnable;
private Boolean cancelled;
private T repeated;

public ExecutiveIterator(Iterator<T> it, ExecutiveRunnable<T> runnable)
{
this.it = it;
this.runnable = runnable;
this.cancelled = false;
this.repeated = null;
}
private Integer size;

public ExecutiveIterator(List<T> it, ExecutiveRunnable<T> runnable)
{
this.it = it.iterator();
this.size = it.size();
this.runnable = runnable;
this.cancelled = false;
this.repeated = null;
Expand Down Expand Up @@ -71,7 +63,7 @@ public T next()

public int size()
{
return Iterators.size(it);
return size;
}

public boolean isCancelled()
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Phantom
main: org.cyberpwn.phantom.Phantom
version: 1.1
version: 1.2
commands:
phantom:
aliases: [ph, p, phan, pha]

0 comments on commit 4655563

Please sign in to comment.