在好例子网,分享、交流、成长!
您当前所在位置:首页Java 开发实例Java语言基础 → java Netty 框架例子源码

java Netty 框架例子源码

Java语言基础

下载此实例
  • 开发语言:Java
  • 实例大小:35.79M
  • 下载次数:815
  • 浏览次数:746
  • 发布时间:2014-11-10
  • 实例类别:Java语言基础
  • 发 布 人:zhou_long1212
  • 所需积分:0
 相关标签: Netty

实例介绍

【实例简介】Netty 提供异步的、事件驱动的网络应用程序框架和工具,用以快速开发高性能、高可靠性的网络服务器和客户端程序。

【实例截图】

【核心代码】


package com.shadow.mvc.main.view.struts;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.security.core.session.SessionInformation;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.stereotype.Component;

import com.danga.MemCached.MemCachedClient;
import com.shadow.mvc.base.view.IAction;
import com.shadow.mvc.domain.model.Page;
import com.shadow.mvc.domain.model.Service;
import com.shadow.mvc.main.domain.Brand;
import com.shadow.mvc.main.domain.Group;
import com.shadow.mvc.main.domain.User;
import com.shadow.mvc.main.service.GroupService;
import com.shadow.mvc.main.service.UserService;
import com.shadow.mvc.support.view.ActionSupport;
import com.shadow.util.base.Utils;
import com.shadow.util.common.FreemarkerUtil;

/**
 * 用户模块控制实现
 * 
 * @author shadow
 * 
 */
@SuppressWarnings("serial")
@Component("userAction")
@Scope("prototype")
public class UserAction extends ActionSupport implements IAction {

	private UserService userService;
	private GroupService groupService;
	private SessionRegistry sessionRegistry;

	private User user;
	private String array;

	private List<Group> allotGroup;
	private List<Group> notAllotGroup;

	private String language;

	private Service service;

	private Page<User> page;

	private MemCachedClient memCachedClient;

	// 检测用户名是否存在
	public String checkUser() {
		service = this.userService.checkUser(user.getUsername());
		flush(toJSON(service));
		return NONE;
	}

	public String add() {
		service = this.userService.save(user);
		flush(toJSON(service));
		return NONE;
	}

	@Override
	public String edit() {
		service = this.userService.modify(user);
		flush(toJSON(service));
		return NONE;
	}

	public String findById() {
		user = (User) this.userService.findById(user).getValue();
		return "findById";
	}

	@SuppressWarnings("unchecked")
	public String findByIdForAllot() {
		user = (User) this.userService.findById(user).getValue();
		allotGroup = (List<Group>) this.groupService.findAllotGroup(user, 1)
				.getValue();
		notAllotGroup = (List<Group>) this.groupService.findAllotGroup(user, 2)
				.getValue();
		return "findByIdForAllot";
	}

	@SuppressWarnings("unchecked")
	public String pageTotal() {
		Integer total = ((Page<Brand>) this.userService
				.findForPage(getParams()).getValue()).getTotal();
		flush(total);
		return NONE;
	}

	@SuppressWarnings("unchecked")
	public String page() {
		page = (Page<User>) this.userService.findForPage(getParams())
				.getValue();
		return "page";
	}

	public String removeById() {
		service = this.userService.removeById(user);
		flush(toJSON(service));
		return NONE;
	}

	public String removeForAll() {
		service = this.userService.removeForAll(array);
		flush(toJSON(service));
		return NONE;
	}

	/** 测试MemCachedClient */
	public void testMemCachedClient() {
		memCachedClient.set("key", "我是存放起来的值");
		System.out.println("通过memcached获取的值: "   memCachedClient.get("key"));
	}

	/** 统计在线人数 */
	public void onlineUsers() {
		System.out
				.println("当前用户数:"   sessionRegistry.getAllPrincipals().size());
	}

	/** 把当前用户踢出系统 */
	public void shotOff() {
		System.out.println(sessionRegistry.getAllPrincipals().size()
				  "___________");
		// 遍历所有用户
		for (Object o : sessionRegistry.getAllPrincipals()) {
			User user = (User) o;
			System.out.println(user.getId()   "__"   user.getUsername());
			for (SessionInformation information : sessionRegistry
					.getAllSessions(o, false)) {
				information.expireNow();
				sessionRegistry.removeSessionInformation(information
						.getSessionId());
			}
		}
	}

	public void test() {

	}

	/** 多语言测试 */
	public String language() {
		Utils.ContextUtil.setLocale(Utils.LanguageUtil.getLocale(language));
		fillTextParams();
		return "language";
	}

	public void test2() {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("message", "这是由FREEMARKER生成的HTML!");
		String url = FreemarkerUtil.getInstance().creat(
				"WEB-INF/ftl/index.html", "sss/sss", "aabs.html", params);
		System.out.println(url);
	}

	public String welcome() {
		return "welcome";
	}

	public String info_login() {
		user = (User) Utils.SecurityUtil.getUserDetails();
		return "info_login";
	}

	public String info_own() {
		user = (User) Utils.SecurityUtil.getUserDetails();
		return "info_own";
	}

	public String logout() {
		return "logout";
	}

	// ======================SET,GET======================

	public String getArray() {
		return array;
	}

	public void setArray(String array) {
		this.array = array;
	}

	public SessionRegistry getSessionRegistry() {
		return sessionRegistry;
	}

	@Resource(name = "sessionRegistry")
	public void setSessionRegistry(SessionRegistry sessionRegistry) {
		this.sessionRegistry = sessionRegistry;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public UserService getUserService() {
		return userService;
	}

	@Resource(name = "userService")
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public GroupService getGroupService() {
		return groupService;
	}

	@Resource(name = "groupService")
	public void setGroupService(GroupService groupService) {
		this.groupService = groupService;
	}

	public List<Group> getAllotGroup() {
		return allotGroup;
	}

	public void setAllotGroup(List<Group> allotGroup) {
		this.allotGroup = allotGroup;
	}

	public List<Group> getNotAllotGroup() {
		return notAllotGroup;
	}

	public void setNotAllotGroup(List<Group> notAllotGroup) {
		this.notAllotGroup = notAllotGroup;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public Service getService() {
		return service;
	}

	public void setService(Service service) {
		this.service = service;
	}

	public Page<User> getPage() {
		return page;
	}

	public void setPage(Page<User> page) {
		this.page = page;
	}

	public MemCachedClient getMemCachedClient() {
		return memCachedClient;
	}

	@Resource(name = "memCachedClient")
	public void setMemCachedClient(MemCachedClient memCachedClient) {
		this.memCachedClient = memCachedClient;
	}

} 


标签: Netty

实例下载地址

java Netty 框架例子源码

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
;
报警