本文整理汇总了Java中com.google.common.eventbus.Subscribe类的典型用法代码示例。如果您正苦于以下问题:Java Subscribe类的具体用法?Java Subscribe怎么用?Java Subscribe使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Subscribe类属于com.google.common.eventbus包,在下文中一共展示了Subscribe类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSelectionResized
import com.google.common.eventbus.Subscribe; //导入依赖的package包/类
@Subscribe
public void onSelectionResized(SelectionResizeEvent event) {
if (timelineModel.getSelectedKeyFrame() == null) {
return;
}
if (event.getType() == START) {
startValues = new HashMap<>();
filterByKeyAndForEach(getKeyValues(), NodeModel::isSelected, this::storeStartKeyValues);
} else if (event.getType() == DRAG) {
event.getNewPositions().keySet().forEach(node -> moveNode(node, event));
} else if (event.getType() == FINISHED) {
Map<KeyValueModel, Object> endValues = getEndValues(event);
if (startValues != null && anyNodeMoved(endValues)) {
commandStack.append(new NodeDragCommand(startValues, endValues, timelineModel, sceneModel));
}
}
}
示例2: onTwitchHostInEvent
import com.google.common.eventbus.Subscribe; //导入依赖的package包/类
@Subscribe
public void onTwitchHostInEvent(TwitchHostInEvent event) {
User channel = usersService.getUser(event.getChannelName());
boolean isCooldownExpired = isCooldownExpired(channel);
if (isCooldownExpired) {
hostRecordService.recordIncomingHost(channel, event.isAuto());
if (settings.getReward() > 0) {
pointsService.give(channel, settings.getReward());
}
Template template = templateDao.getByKey(HostWatchComponent.INCOMING_HOST_NOTICE_TEMPLATE);
assert template != null; // Template cannot be null since it's set during install/update
if (StringUtils.isNotEmpty(template.getTemplate())) {
chat.say(Templater.template(template.getTemplate())
.add("username", channel::getDisplayName)
.add("points", pointsService.asString(settings.getReward())));
}
}
}
示例3: applicationThemeRequestCallback
import com.google.common.eventbus.Subscribe; //导入依赖的package包/类
@Subscribe
public void applicationThemeRequestCallback(ThemeRequestCallback event)
{
if (event.requestedTheme().isPresent())
{
Theme applicationTheme = event.requestedTheme().get();
try
{
stage.getScene().getStylesheets().clear();
stage.getScene().getStylesheets().add(applicationTheme.getPath());
return;
}
catch (MalformedURLException e)
{
console.warning("Unable to load application theme "
+ applicationTheme.getName());
return;
}
}
console.warning("Unable to load application theme.");
}
示例4: testWatchOpen
import com.google.common.eventbus.Subscribe; //导入依赖的package包/类
@Test
public void testWatchOpen(@Mocked ServiceRegistryConfig serviceRegistryConfig,
@Mocked ServiceRegistryClient srClient,
@Mocked Microservice microservice) {
initWatch(serviceRegistryConfig, srClient, microservice);
new MockUp<ServiceRegistryClient>(srClient) {
@Mock
void watch(String selfMicroserviceId, AsyncResultCallback<MicroserviceInstanceChangedEvent> callback,
AsyncResultCallback<Void> onOpen, AsyncResultCallback<Void> onClose) {
onOpen.success(null);
}
};
Holder<Boolean> openHolder = new Holder<>();
eventBus.register(new Object() {
@Subscribe
public void onOpen(RecoveryEvent event) {
openHolder.value = true;
}
});
Assert.assertNull(openHolder.value);
microserviceWatchTask.run();
Assert.assertTrue(openHolder.value);
}
示例5: testWatchFailed
import com.google.common.eventbus.Subscribe; //导入依赖的package包/类
@Test
public void testWatchFailed(@Mocked ServiceRegistryConfig serviceRegistryConfig,
@Mocked ServiceRegistryClient srClient,
@Mocked Microservice microservice) {
initWatch(serviceRegistryConfig, srClient, microservice);
new MockUp<ServiceRegistryClient>(srClient) {
@Mock
void watch(String selfMicroserviceId, AsyncResultCallback<MicroserviceInstanceChangedEvent> callback,
AsyncResultCallback<Void> onOpen, AsyncResultCallback<Void> onClose) {
callback.fail(new Error("test failed"));
}
};
Holder<Throwable> holder = new Holder<>();
eventBus.register(new Object() {
@Subscribe
public void onException(ExceptionEvent event) {
holder.value = event.getThrowable();
}
});
Assert.assertNull(holder.value);
microserviceWatchTask.run();
Assert.assertEquals("test failed", holder.value.getMessage());
}
示例6: onShowGraph
import com.google.common.eventbus.Subscribe; //导入依赖的package包/类
@Subscribe
public void onShowGraph(ShowGraphEvent event) {
Synset rootSynset = service.synsetRemote().findSynsetBySense(event.getSense(), Arrays.asList(1l, 2l, 3l));
ui.releaseDataSetCache();
if (rootSynset != null) {
Map<Long, DataEntry> entries = service.synsetRemote()
.prepareCacheForRootNode(rootSynset, Arrays.asList(1l, 2l, 3l),
new NodeDirection[]{NodeDirection.LEFT,NodeDirection.TOP, NodeDirection.BOTTOM, NodeDirection.RIGHT});
if (entries != null) {
ui.setEntrySets((HashMap<Long, DataEntry>) entries);
}
//pobieranie synsetu z wcześniej pobranej mapy, aby otrzymać obiekt, który ma relacje (nie są leniwymi kolekcjami)
DataEntry dataEntry = entries.get(rootSynset.getId());
if (dataEntry != null) {
rootSynset = dataEntry.getSynset();
}
ui.refreshView(rootSynset);
} else {
ui.clear();
}
}
示例7: updateTileViewModel
import com.google.common.eventbus.Subscribe; //导入依赖的package包/类
@Subscribe
public final void updateTileViewModel( final BuildTypeData data ) {
if ( data != _buildTypeData )
return;
Platform.runLater( ( ) -> {
_displayedName.set( Strings.isNullOrEmpty( data.getAliasName( ) ) ? data.getName( ) : data.getAliasName( ) );
_running.setValue( data.hasRunningBuild( ) );
_queued.setValue( data.isQueued( ) );
updateLastFinishedDate( );
updateTimeLeft( );
updatePercentageComplete( );
updateBackground( );
updateIcon( );
} );
}
示例8: layoutDone
import com.google.common.eventbus.Subscribe; //导入依赖的package包/类
/**
* Retrieves metadata as soon as the layout is done.
*
* @param event a {@link LayoutDoneEvent}
*/
@Subscribe
public void layoutDone(final LayoutDoneEvent event) {
if (currentRadius >= RADIUS_THRESHOLD) {
retrievalExecutor.stop();
return;
}
retrievalExecutor.run(() -> {
retrieveMetadata(gfaFile, event.getSubgraph());
if (Thread.interrupted()) {
return;
}
pathCalculator.computePaths(event.getSubgraph());
HygeneEventBus.getInstance().post(new NodeMetadataCacheUpdateEvent(event.getSubgraph()));
});
}
示例9: onTextMessage
import com.google.common.eventbus.Subscribe; //导入依赖的package包/类
@Subscribe
public void onTextMessage(MessageReceivedEvent event) {
CGuild cGuild = charrizard.getCGuildManager().getGuild(event.getGuild());
if (cGuild == null) {
charrizard.getCGuildManager().createGuild(event.getGuild());
cGuild = charrizard.getCGuildManager().getGuild(event.getGuild());
}
if (!event.getMessage().getContent().startsWith(prefix)) {
CTextChannel cTextChannel = cGuild.getTextChannel(event.getTextChannel());
if (cTextChannel == null) {
cGuild.createTextChannel(event.getTextChannel());
cTextChannel = cGuild.getTextChannel(event.getTextChannel());
}
cTextChannel.addMessage();
return;
}
String[] args = event.getMessage().getContent().split(" ");
args[0] = args[0].substring(1);
Command command = commands.stream().filter(c -> c.getLabel().equals(args[0])).findFirst().orElse(null);
if (command == null) {
return;
}
cGuild.runCommand(command, new CMessage(event.getMessage()), args);
}
示例10: testAnonymous
import com.google.common.eventbus.Subscribe; //导入依赖的package包/类
public void testAnonymous() {
final AtomicReference<String> holder = new AtomicReference<String>();
final AtomicInteger deliveries = new AtomicInteger();
EventBus bus = new EventBus();
bus.register(new Object() {
@Subscribe
public void accept(String str) {
holder.set(str);
deliveries.incrementAndGet();
}
});
String EVENT = "Hello!";
bus.post(EVENT);
assertEquals("Only one event should be delivered.", 1, deliveries.get());
assertEquals("Correct string should be delivered.", EVENT, holder.get());
}
示例11: onStreamLabsDonationEvent
import com.google.common.eventbus.Subscribe; //导入依赖的package包/类
@Subscribe
public void onStreamLabsDonationEvent(StreamLabsDonationEvent event) {
User user = usersService.getUser(event.getUsername());
if (user != null) {
double reward = (event.getAmount() * DonationRegisterConstants.POINTS_MULTIPLIER);
donationsService.registerDonation(user, event.getFormattedAmount(), event.getMessage());
pointsService.give(user, reward);
Template template = templateDao.getByKey(DonationRegisterConstants.INCOMING_DONATION_NOTICE);
assert template != null; // Template cannot be null since it's set during install/update
if (StringUtils.isNotEmpty(template.getTemplate())) {
chat.say(Templater.template(template.getTemplate())
.add("username", user::getDisplayName)
.add("points", pointsService.asString(reward))
.add("formattedamount", event::getFormattedAmount)
.add("message", event::getMessage));
}
}
}
示例12: registerWatchResult
import com.google.common.eventbus.Subscribe; //导入依赖的package包/类
@SuppressWarnings("restriction")
@Subscribe
public void registerWatchResult(RegWatchResponseEvent e) {
if (!e.isSuccess())
throw new IllegalArgumentException("There isn't a register with the name "
+ e.getRegisterName());
String id = e.getRegisterID();
String registerName = e.getRegisterName();
LongProperty register = e.getRegObject();
System.out.println("suc" + id + " -- " + registerName + " -- " + register);
register.addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
//watchedRegisters.refresh();
System.out.println("Success" + id + " -- " + registerName + " -- " + register);
session.setAttribute("idd", register.getValue());
//System.out.println("id is: " + session.getAttribute("idd"));
}
});
}
示例13: onConsoleInputEvent
import com.google.common.eventbus.Subscribe; //导入依赖的package包/类
@Subscribe
public void onConsoleInputEvent(ConsoleInputEvent event) {
char identifier = event.getIdentifier();
switch (identifier) {
case PREFIX_COMMAND:
runCommand(event);
break;
case PREFIX_CMD_COMMAND:
executeConsoleCommand(event);
break;
case PREFIX_WHISPER:
doWhisper(event);
break;
case PREFIX_SAY:
doSay(event);
break;
default:
break;
}
}
示例14: toggleSettingsPane
import com.google.common.eventbus.Subscribe; //导入依赖的package包/类
@Subscribe
private void toggleSettingsPane(ToggleEvent e){
Platform.runLater(()-> {
if (e == ToggleEvent.SHOW_SETTINGS && !showSettings){
settingsPane.toFront();
showSettings = true;
}else if (e == ToggleEvent.HIDE_SETTINGS && showSettings){
settingsPane.toBack();
showSettings = false;
}else if (e == ToggleEvent.TOGGLE_SETTINGS){
if (showSettings){
settingsPane.toBack();
}else{
settingsPane.toFront();
}
showSettings = !showSettings;
}
});
}
示例15: toggleRoomSettings
import com.google.common.eventbus.Subscribe; //导入依赖的package包/类
@Subscribe
private void toggleRoomSettings(ToggleEvent e) {
if (e == ToggleEvent.SHOW_ROOM_SETTINGS && !showRoomSettings) {
settingsPane.toFront();
showRoomSettings = true;
} else if (e == ToggleEvent.HIDE_ROOM_SETTINGS && showRoomSettings) {
settingsPane.toBack();
showRoomSettings = false;
} else if (e == ToggleEvent.TOGGLE_ROOM_SETTINGS) {
if (showRoomSettings) {
settingsPane.toBack();
} else {
settingsPane.toFront();
}
showRoomSettings = !showRoomSettings;
}
}