(CNN) A Missouri man ambushed and killed three law officers and wounded three others in Baton Rouge on Sunday during a time when police nationwide and in the Louisiana city in particular have been on high alert after five officers were killed in a Dallas ambush July 7.

Louisiana State Police announced last week that they had received threats of plots against Baton Rouge police.

On Sunday, a man identified as Gavin Long of Kansas City went on a shooting rampage on his 29th birthday that left two police officers and a sheriff's deputy dead, police sources said. Long, who was African-American, was a former Marine who spent time in Iraq and was discharged at the rank of sergeant in 2010, according to the U.S. military.

Police officers who responded to Sunday's shootings killed Long in a gunbattle after the other officers were ambushed, police sources told CNN. The murder weapon was an AR-15 style semi-automatic rifle, law enforcement sources told CNN.

Police have not officially released the names of the victims but one was identified by family members as Officer Montrell Jackson . Law officers Matthew Gerald and Brad Garafola were also killed, according to sources close to the department. That was corroborated with social media posts.

The three law-enforcement officers killed in Baton Rough, Louisiana, were, from left, Montrell Jackson, Brad Garafola and Matthew Gerald.

The gunman also critically wounded a deputy who is "fighting for his life," said East Baton Rouge Parish Sheriff Sid Gautreaux. Another wounded deputy and police officer have non-life-threatening wounds, law officers said.

Jackson had posted on Facebook on July 8 how physically and emotionally drained he had been since protests had erupted in Baton Rouge after the July 5 killing of Alton Sterling by police.

"I swear to God I love this city, but I wonder if this city loves me. In uniform I get nasty, hateful looks and out of uniform some consider me a threat. ... These are trying times. Please don't let hate infect your heart."

Gunman made frequent web posts

Long was a prolific user of social media, with dozens of videos, podcasts, tweets and posts under his pseudonym Cosmo Setepenra. Under that name, Long also tweeted a link to a news story about Dallas shooter Micah Johnson and said the shooter was "one of us! # MY Religion is Justice."

A law enforcement source said Long "was not alone during his stay in Baton Rouge," but it's unclear if others he was with knew about or were actively involved in any plot.

Police gave the name of the man who shot 6 police officers in Baton Rouge on July 17 as Gavin Long. Online, he used the name "Cosmo Setepenra," and posted on a YouTube channel of that name.

The FBI is running down names of possible associates, another law enforcement official said.

In YouTube videos posted July 8 and 10, reviewed by CNN, Long, using the name "Cosmo," spoke about the need for "fighting back" and what people should say about him "if anything happened to me."

In the July 10 video, recorded, he said, in Dallas, he says, "Zero have been successful just over simple protesting."

"You gotta fight back," he says on the video.

Two law enforcement sources tell CNN that Long rented a car in Kansas City after the Dallas shootings and drove it to Baton Rouge. Given that Long posted a YouTube video from Dallas on July 10, it is likely he drove to Baton Rouge via Dallas.

Calls for end to violence

Quinyetta McMillon, mother of Sterling's son Cameron, put out a statement through her lawyers condemning the ambush.

"We are disgusted by the despicable act of violence today that resulted in the shooting deaths of members of the Baton Rouge law enforcement. My family is heartbroken for the officers and their families. ... We reject violence of any kind directed at members of law enforcement or citizens.

My hope is that one day soon we can come together and find solutions to the very important issues facing our nation rather than continuing to hurt one another."

President Barack Obama on Sunday condemned the killings and all attacks on law enforcement.

"We as a nation have to be loud and clear that nothing justifies violence against law enforcement," Obama said, speaking from the White House press briefing room. "Attacks on police are an attack on all of us and the rule of law that makes society possible." In a written statement earlier in the day, Obama called the Baton Rough shootings a "cowardly and reprehensible assault."

'No talking, just shooting'

The shooting Sunday took place around 8:40 a.m. (9:40 a.m. ET) in the city of about 230,000 people, already tense after the high-profile police shooting of Sterling, an African-American man, on July 5.

On Sunday, police received a call of a "suspicious person walking down Airline Highway with an assault rifle," a source with knowledge of the investigation told CNN.

When police arrived, the shooting began.

"There was no talking, just shooting," Baton Rouge Police Cpl. L.J. McKneely said.

At an afternoon news conference, local and state authorities, including Louisiana Gov. John Bel Edwards, said Long was thought to be the lone gunman. Earlier reports had said authorities believed there might have been more than one attacker. Edwards described the shooting as an "absolutely unspeakable heinous attack."

Gunman followed conspiracy groups

Long had at least two websites where he described himself as a "Freedom Strategist, Mental Game Coach, Nutritionist, Author and Spiritual Adviser," according to a CNN review of the websites.

In addition, Long followed several conspiracy groups devoted to government surveillance and monitoring. CNN found that an email address linked to Long showed he was a member of a support group in an organization called Freedom from Covert Harassment and Surveillance, whose mission is to help those "Marginalized and abused by... Remote Brain experimentation, Remote Neural Monitoring of an entire Humans Body."

The FBI is vetting the gunman's claims he was a member of the Nation of Islam. An official said the belief is that Long identified as being associated with the black separatist movement in some capacity but there is no indication he was directed by it. The law enforcement official said the FBI has no indication any black separatist or other domestic terrorist groups are supporting or sending people to kill cops.

In the July 8 YouTube video, Long says he acted on his own and that he wasn't directed by any group.

"I just wanted to let y'all know, don't affiliate me with nothing," he says. "I thought my own stuff; I made my own decisions; I'm the one who gotta listen to the judgment."

LSU Police armed with rifles several blocks away from the scene @WBRZ pic.twitter.com/VhkqfMOpOd — Michael Vinsanau (@MVinsanau) July 17, 2016

Police had been on alert

Since the shooting death of Sterling by Baton Rouge police , the department has worried about threats against officers.

It has been an emotionally charged few days across the country because of the protests stemming from the Sterling shooting and the shooting by police of Philando Castile in Minnesota, plus the ambush on Dallas police officers in which a sniper killed five officers.

"This is an unspeakable and unjustified attack on all of us at a time when we need unity and healing," Edwards said Sunday in the hours after the Baton Rouge shooting.