INTSAMPLES-95 Add Remote Monitor

INTSAMPLES-95 Add OperationInvokingAdapter

For reference see: https://jira.springsource.org/browse/INTSAMPLES-95
This commit is contained in:
Gary Russell
2012-10-11 12:33:38 -04:00
committed by Gunnar Hillert
parent 1a2ecaf254
commit ee8de8c6b0
11 changed files with 346 additions and 199 deletions

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2002-2010 the original author or authors
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.model;
@@ -22,109 +22,109 @@ import java.util.Date;
*/
public class TwitterMessage {
private Date createdAt;
private String text;
private String fromUser;
private String profileImageUrl;
private Date createdAt;
private String text;
private String fromUser;
private String profileImageUrl;
/** Default constructor. */
public TwitterMessage() {
super();
}
/** Default constructor. */
public TwitterMessage() {
super();
}
/** Constructor to initialize all fields available. */
public TwitterMessage(Date createdAt, String text, String fromUser,
String profileImageUrl) {
super();
this.createdAt = createdAt;
this.text = text;
this.fromUser = fromUser;
this.profileImageUrl = profileImageUrl;
}
/** Constructor to initialize all fields available. */
public TwitterMessage(Date createdAt, String text, String fromUser,
String profileImageUrl) {
super();
this.createdAt = createdAt;
this.text = text;
this.fromUser = fromUser;
this.profileImageUrl = profileImageUrl;
}
public Date getCreatedAt() {
return createdAt;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public String getText() {
return text;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public void setText(String text) {
this.text = text;
}
public String getFromUser() {
return fromUser;
}
public String getFromUser() {
return fromUser;
}
public void setFromUser(String fromUser) {
this.fromUser = fromUser;
}
public void setFromUser(String fromUser) {
this.fromUser = fromUser;
}
public String getProfileImageUrl() {
return profileImageUrl;
}
public String getProfileImageUrl() {
return profileImageUrl;
}
public void setProfileImageUrl(String profileImageUrl) {
this.profileImageUrl = profileImageUrl;
}
public void setProfileImageUrl(String profileImageUrl) {
this.profileImageUrl = profileImageUrl;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((createdAt == null) ? 0 : createdAt.hashCode());
result = prime * result
+ ((fromUser == null) ? 0 : fromUser.hashCode());
result = prime * result
+ ((profileImageUrl == null) ? 0 : profileImageUrl.hashCode());
result = prime * result + ((text == null) ? 0 : text.hashCode());
return result;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((createdAt == null) ? 0 : createdAt.hashCode());
result = prime * result
+ ((fromUser == null) ? 0 : fromUser.hashCode());
result = prime * result
+ ((profileImageUrl == null) ? 0 : profileImageUrl.hashCode());
result = prime * result + ((text == null) ? 0 : text.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TwitterMessage other = (TwitterMessage) obj;
if (createdAt == null) {
if (other.createdAt != null)
return false;
} else if (!createdAt.equals(other.createdAt))
return false;
if (fromUser == null) {
if (other.fromUser != null)
return false;
} else if (!fromUser.equals(other.fromUser))
return false;
if (profileImageUrl == null) {
if (other.profileImageUrl != null)
return false;
} else if (!profileImageUrl.equals(other.profileImageUrl))
return false;
if (text == null) {
if (other.text != null)
return false;
} else if (!text.equals(other.text))
return false;
return true;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TwitterMessage other = (TwitterMessage) obj;
if (createdAt == null) {
if (other.createdAt != null)
return false;
} else if (!createdAt.equals(other.createdAt))
return false;
if (fromUser == null) {
if (other.fromUser != null)
return false;
} else if (!fromUser.equals(other.fromUser))
return false;
if (profileImageUrl == null) {
if (other.profileImageUrl != null)
return false;
} else if (!profileImageUrl.equals(other.profileImageUrl))
return false;
if (text == null) {
if (other.text != null)
return false;
} else if (!text.equals(other.text))
return false;
return true;
}
@Override
public String toString() {
return "Tweet [createdAt=" + createdAt + ", text=" + text
+ ", fromUser=" + fromUser + ", profileImageUrl="
+ profileImageUrl + "]";
}
@Override
public String toString() {
return "Tweet [createdAt=" + createdAt + ", text=" + text
+ ", fromUser=" + fromUser + ", profileImageUrl="
+ profileImageUrl + "]";
}
}

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2002-2010 the original author or authors
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.mvc.controller;
@@ -33,56 +33,56 @@ import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class HomeController {
private static final Log logger = LogFactory.getLog(HomeController.class);
private static final Log logger = LogFactory.getLog(HomeController.class);
@Autowired
private TwitterService twitterService;
@Autowired
private TwitterService twitterService;
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value="/")
public String home(Model model, @RequestParam(required=false) String startTwitter,
@RequestParam(required=false) String stopTwitter,
@RequestParam(required=false) String shutdown) {
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value="/")
public String home(Model model, @RequestParam(required=false) String startTwitter,
@RequestParam(required=false) String stopTwitter,
@RequestParam(required=false) String shutdown) {
if (startTwitter != null) {
twitterService.startTwitterAdapter();
return "redirect:/";
}
if (startTwitter != null) {
twitterService.startTwitterAdapter();
return "redirect:/";
}
if (stopTwitter != null) {
twitterService.stopTwitterAdapter();
return "redirect:/";
}
if (stopTwitter != null) {
twitterService.stopTwitterAdapter();
return "redirect:/";
}
if (shutdown != null) {
twitterService.shutdown();
return "redirect:/";
}
if (shutdown != null) {
twitterService.shutdown();
return "redirect:/";
}
final Collection<TwitterMessage> twitterMessages = twitterService.getTwitterMessages();
final Collection<TwitterMessage> twitterMessages = twitterService.getTwitterMessages();
logger.info("Retrieved " + twitterMessages.size() + " Twitter messages.");
logger.info("Retrieved " + twitterMessages.size() + " Twitter messages.");
model.addAttribute("twitterMessages", twitterMessages);
model.addAttribute("twitterMessages", twitterMessages);
return "home";
}
return "home";
}
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value="/ajax")
public String ajaxCall(Model model) {
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value="/ajax")
public String ajaxCall(Model model) {
final Collection<TwitterMessage> twitterMessages = twitterService.getTwitterMessages();
final Collection<TwitterMessage> twitterMessages = twitterService.getTwitterMessages();
logger.info("Retrieved " + twitterMessages.size() + " Twitter messages.");
model.addAttribute("twitterMessages", twitterMessages);
logger.info("Retrieved " + twitterMessages.size() + " Twitter messages.");
model.addAttribute("twitterMessages", twitterMessages);
return "twitterMessages";
return "twitterMessages";
}
}
}

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2002-2010 the original author or authors
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.service;

View File

@@ -33,7 +33,7 @@ public class DummyTwitter {
"Spring Integration is the coolest Enterprise Integration project",
new Date(),
"SomeUser",
null,
"http://a0.twimg.com/profile_images/1598911687/ICO_S2_Bug_normal.png",
0L,
0L,
null,

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springintegration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* This class demonstrates the use a Spring Integration jmx adadpers to receive
* notifications, poll attributes, and invoke operations on a Remote JMX MBeanServer.
*
* @author Gary Russell
* @since 2.2
*
*/
public class NotificationListener {
public static void main(String[] args) throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:/META-INF/spring/integration/remote-monitor-context.xml");
Gateway gw = ctx.getBean(Gateway.class);
int cmd = 0;
while (cmd != 'q') {
cmd = System.in.read();
gw.send((char) cmd);
}
}
public static interface Gateway {
void send(char command);
}
}